sun.net.www.ParseUtil Java Examples
The following examples show how to use
sun.net.www.ParseUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtpURLConnection.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(checkURL(url)); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example #2
Source File: MailToURLConnection.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public synchronized OutputStream getOutputStream() throws IOException { if (os != null) { return os; } else if (is != null) { throw new IOException("Cannot write output after reading input."); } connect(); String to = ParseUtil.decode(url.getPath()); client.from(getFromAddress()); client.to(to); os = client.startMessage(); return os; }
Example #3
Source File: JarURLConnection.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private void parseSpecs(URL url) throws MalformedURLException { String spec = url.getFile(); int separator = spec.indexOf("!/"); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no !/ found in url spec:" + spec); } jarFileURL = new URL(spec.substring(0, separator++)); entryName = null; /* if ! is the last letter of the innerURL, entryName is null */ if (++separator != spec.length()) { entryName = spec.substring(separator, spec.length()); entryName = ParseUtil.decode (entryName); } }
Example #4
Source File: MailToURLConnection.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public synchronized OutputStream getOutputStream() throws IOException { if (os != null) { return os; } else if (is != null) { throw new IOException("Cannot write output after reading input."); } connect(); String to = ParseUtil.decode(url.getPath()); client.from(getFromAddress()); client.to(to); os = client.startMessage(); return os; }
Example #5
Source File: FtpURLConnection.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(url); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example #6
Source File: JavaRuntimeURLConnection.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
JavaRuntimeURLConnection(URL url) throws IOException { super(url); String path = url.getPath(); if (path.length() == 0 || path.charAt(0) != '/') throw new MalformedURLException(url + " missing path or /"); if (path.length() == 1) { this.module = null; this.name = null; } else { int pos = path.indexOf('/', 1); if (pos == -1) { this.module = path.substring(1); this.name = null; } else { this.module = path.substring(1, pos); this.name = ParseUtil.decode(path.substring(pos+1)); } } }
Example #7
Source File: FtpURLConnection.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(url); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example #8
Source File: ParseUtil_4922813.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] argv) throws Exception { int num = 400; while (num-- >= 0) { String source = getTestSource(); String ec = sun.net.www.ParseUtil.encodePath(source); String v117 = ParseUtil_V117.encodePath(source); if (!ec.equals(v117)) { throw new RuntimeException("Test Failed for : \n" + " source =<" + getUnicodeString(source) + ">"); } } }
Example #9
Source File: ParseUtil_4922813.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void main(String[] argv) throws Exception { int num = 400; while (num-- >= 0) { String source = getTestSource(); String ec = sun.net.www.ParseUtil.encodePath(source); String v117 = ParseUtil_V117.encodePath(source); if (!ec.equals(v117)) { throw new RuntimeException("Test Failed for : \n" + " source =<" + getUnicodeString(source) + ">"); } } }
Example #10
Source File: FtpURLConnection.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(url); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example #11
Source File: FileURLMapper.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * @returns the platform specific path corresponding to the URL, and in particular * returns a UNC when the authority contains a hostname */ public String getPath () { if (file != null) { return file; } String host = url.getHost(); if (host != null && !host.equals("") && !"localhost".equalsIgnoreCase(host)) { String rest = url.getFile(); String s = host + ParseUtil.decode (url.getFile()); file = "\\\\"+ s.replace('/', '\\'); return file; } String path = url.getFile().replace('/', '\\'); file = ParseUtil.decode(path); return file; }
Example #12
Source File: ParseUtil_4922813.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] argv) throws Exception { int num = 400; while (num-- >= 0) { String source = getTestSource(); String ec = sun.net.www.ParseUtil.encodePath(source); String v117 = ParseUtil_V117.encodePath(source); if (!ec.equals(v117)) { throw new RuntimeException("Test Failed for : \n" + " source =<" + getUnicodeString(source) + ">"); } } }
Example #13
Source File: FileURLMapper.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * @returns the platform specific path corresponding to the URL, and in particular * returns a UNC when the authority contains a hostname */ public String getPath () { if (file != null) { return file; } String host = url.getHost(); if (host != null && !host.equals("") && !"localhost".equalsIgnoreCase(host)) { String rest = url.getFile(); String s = host + ParseUtil.decode (url.getFile()); file = "\\\\"+ s.replace('/', '\\'); return file; } String path = url.getFile().replace('/', '\\'); file = ParseUtil.decode(path); return file; }
Example #14
Source File: JarURLConnection.java From JDKSourceCode1.8 with MIT License | 6 votes |
private void parseSpecs(URL url) throws MalformedURLException { String spec = url.getFile(); int separator = spec.indexOf("!/"); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no !/ found in url spec:" + spec); } jarFileURL = new URL(spec.substring(0, separator++)); entryName = null; /* if ! is the last letter of the innerURL, entryName is null */ if (++separator != spec.length()) { entryName = spec.substring(separator, spec.length()); entryName = ParseUtil.decode (entryName); } }
Example #15
Source File: JarURLConnection.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void parseSpecs(URL url) throws MalformedURLException { String spec = url.getFile(); int separator = spec.indexOf("!/"); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no !/ found in url spec:" + spec); } jarFileURL = new URL(spec.substring(0, separator++)); entryName = null; /* if ! is the last letter of the innerURL, entryName is null */ if (++separator != spec.length()) { entryName = spec.substring(separator, spec.length()); entryName = ParseUtil.decode (entryName); } }
Example #16
Source File: MailToURLConnection.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public synchronized OutputStream getOutputStream() throws IOException { if (os != null) { return os; } else if (is != null) { throw new IOException("Cannot write output after reading input."); } connect(); String to = ParseUtil.decode(url.getPath()); client.from(getFromAddress()); client.to(to); os = client.startMessage(); return os; }
Example #17
Source File: Package.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static Package defineSystemPackage(final String iname, final String fn) { return AccessController.doPrivileged(new PrivilegedAction<Package>() { public Package run() { String name = iname; // Get the cached code source url for the file name URL url = urls.get(fn); if (url == null) { // URL not found, so create one File file = new File(fn); try { url = ParseUtil.fileToEncodedURL(file); } catch (MalformedURLException e) { } if (url != null) { urls.put(fn, url); // If loading a JAR file, then also cache the manifest if (file.isFile()) { mans.put(fn, loadManifest(fn)); } } } // Convert to "."-separated package name name = name.substring(0, name.length() - 1).replace('/', '.'); Package pkg; Manifest man = mans.get(fn); if (man != null) { pkg = new Package(name, man, url, null); } else { pkg = new Package(name, null, null, null, null, null, null, null, null); } pkgs.put(name, pkg); return pkg; } }); }
Example #18
Source File: SerialVer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
static void initializeLoader(String cp) throws MalformedURLException, IOException { URL[] urls; StringTokenizer st = new StringTokenizer(cp, File.pathSeparator); int count = st.countTokens(); urls = new URL[count]; for (int i = 0; i < count; i++) { urls[i] = ParseUtil.fileToEncodedURL( new File(new File(st.nextToken()).getCanonicalPath())); } loader = new URLClassLoader(urls); }
Example #19
Source File: JarURLConnection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void parseSpecs(URL url) throws MalformedURLException { String spec = url.getFile(); int separator = spec.indexOf("!/"); /* * REMIND: we don't handle nested JAR URLs */ if (separator == -1) { throw new MalformedURLException("no !/ found in url spec:" + spec); } jarFileURL = new URL(spec.substring(0, separator++)); /* * The url argument may have had a runtime fragment appended, so * we need to add a runtime fragment to the jarFileURL to enable * runtime versioning when the underlying jar file is opened. */ if ("runtime".equals(url.getRef())) { jarFileURL = new URL(jarFileURL, "#runtime"); } entryName = null; /* if ! is the last letter of the innerURL, entryName is null */ if (++separator != spec.length()) { entryName = spec.substring(separator, spec.length()); entryName = ParseUtil.decode (entryName); } }
Example #20
Source File: URLClassPath.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
JarLoader(URL url, URLStreamHandler jarHandler, HashMap<String, Loader> loaderMap, AccessControlContext acc) throws IOException { super(new URL("jar", "", -1, url + "!/", jarHandler)); csu = url; handler = jarHandler; lmap = loaderMap; this.acc = acc; if (!isOptimizable(url)) { ensureOpen(); } else { String fileName = url.getFile(); if (fileName != null) { fileName = ParseUtil.decode(fileName); File f = new File(fileName); metaIndex = MetaIndex.forJar(f); // If the meta index is found but the file is not // installed, set metaIndex to null. A typical // senario is charsets.jar which won't be installed // when the user is running in certain locale environment. // The side effect of null metaIndex will cause // ensureOpen get called so that IOException is thrown. if (metaIndex != null && !f.exists()) { metaIndex = null; } } // metaIndex is null when either there is no such jar file // entry recorded in meta-index file or such jar file is // missing in JRE. See bug 6340399. if (metaIndex == null) { ensureOpen(); } } }
Example #21
Source File: FtpURLConnection.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void cd(String path) throws FtpProtocolException, IOException { if (path == null || path.isEmpty()) { return; } if (path.indexOf('/') == -1) { ftp.changeDirectory(ParseUtil.decode(path)); return; } StringTokenizer token = new StringTokenizer(path, "/"); while (token.hasMoreTokens()) { ftp.changeDirectory(ParseUtil.decode(token.nextToken())); } }
Example #22
Source File: Handler.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings("deprecation") protected void parseURL(URL url, String spec, int start, int limit) { String file = null; String ref = null; // first figure out if there is an anchor int refPos = spec.indexOf('#', limit); boolean refOnly = refPos == start; if (refPos > -1) { ref = spec.substring(refPos + 1, spec.length()); if (refOnly) { file = url.getFile(); } } // then figure out if the spec is // 1. absolute (jar:) // 2. relative (i.e. url + foo/bar/baz.ext) // 3. anchor-only (i.e. url + #foo), which we already did (refOnly) boolean absoluteSpec = false; if (spec.length() >= 4) { absoluteSpec = spec.substring(0, 4).equalsIgnoreCase("jar:"); } spec = spec.substring(start, limit); if (absoluteSpec) { file = parseAbsoluteSpec(spec); } else if (!refOnly) { file = parseContextSpec(url, spec); // Canonize the result after the bangslash int bangSlash = indexOfBangSlash(file); String toBangSlash = file.substring(0, bangSlash); String afterBangSlash = file.substring(bangSlash); sun.net.www.ParseUtil canonizer = new ParseUtil(); afterBangSlash = canonizer.canonizeString(afterBangSlash); file = toBangSlash + afterBangSlash; } setURL(url, "jar", "", -1, file, ref); }
Example #23
Source File: Package.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static Package defineSystemPackage(final String iname, final String fn) { return AccessController.doPrivileged(new PrivilegedAction<Package>() { public Package run() { String name = iname; // Get the cached code source url for the file name URL url = urls.get(fn); if (url == null) { // URL not found, so create one File file = new File(fn); try { url = ParseUtil.fileToEncodedURL(file); } catch (MalformedURLException e) { } if (url != null) { urls.put(fn, url); // If loading a JAR file, then also cache the manifest if (file.isFile()) { mans.put(fn, loadManifest(fn)); } } } // Convert to "."-separated package name name = name.substring(0, name.length() - 1).replace('/', '.'); Package pkg; Manifest man = mans.get(fn); if (man != null) { pkg = new Package(name, man, url, null); } else { pkg = new Package(name, null, null, null, null, null, null, null, null); } pkgs.put(name, pkg); return pkg; } }); }
Example #24
Source File: FtpURLConnection.java From Bytecoder with Apache License 2.0 | 5 votes |
private void cd(String path) throws FtpProtocolException, IOException { if (path == null || path.isEmpty()) { return; } if (path.indexOf('/') == -1) { ftp.changeDirectory(ParseUtil.decode(path)); return; } StringTokenizer token = new StringTokenizer(path, "/"); while (token.hasMoreTokens()) { ftp.changeDirectory(ParseUtil.decode(token.nextToken())); } }
Example #25
Source File: URLClassPath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
JarLoader(URL url, URLStreamHandler jarHandler, HashMap<String, Loader> loaderMap) throws IOException { super(new URL("jar", "", -1, url + "!/", jarHandler)); csu = url; handler = jarHandler; lmap = loaderMap; if (!isOptimizable(url)) { ensureOpen(); } else { String fileName = url.getFile(); if (fileName != null) { fileName = ParseUtil.decode(fileName); File f = new File(fileName); metaIndex = MetaIndex.forJar(f); // If the meta index is found but the file is not // installed, set metaIndex to null. A typical // senario is charsets.jar which won't be installed // when the user is running in certain locale environment. // The side effect of null metaIndex will cause // ensureOpen get called so that IOException is thrown. if (metaIndex != null && !f.exists()) { metaIndex = null; } } // metaIndex is null when either there is no such jar file // entry recorded in meta-index file or such jar file is // missing in JRE. See bug 6340399. if (metaIndex == null) { ensureOpen(); } } }
Example #26
Source File: ModuleReferences.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override Optional<URI> implFind(String name) throws IOException { JarEntry je = getEntry(name); if (je != null) { if (jf.isMultiRelease()) name = SharedSecrets.javaUtilJarAccess().getRealName(jf, je); if (je.isDirectory() && !name.endsWith("/")) name += "/"; String encodedPath = ParseUtil.encodePath(name, false); String uris = "jar:" + uri + "!/" + encodedPath; return Optional.of(URI.create(uris)); } else { return Optional.empty(); } }
Example #27
Source File: URLClassPath.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
JarLoader(URL url, URLStreamHandler jarHandler, HashMap<String, Loader> loaderMap) throws IOException { super(new URL("jar", "", -1, url + "!/", jarHandler)); csu = url; handler = jarHandler; lmap = loaderMap; if (!isOptimizable(url)) { ensureOpen(); } else { String fileName = url.getFile(); if (fileName != null) { fileName = ParseUtil.decode(fileName); File f = new File(fileName); metaIndex = MetaIndex.forJar(f); // If the meta index is found but the file is not // installed, set metaIndex to null. A typical // senario is charsets.jar which won't be installed // when the user is running in certain locale environment. // The side effect of null metaIndex will cause // ensureOpen get called so that IOException is thrown. if (metaIndex != null && !f.exists()) { metaIndex = null; } } // metaIndex is null when either there is no such jar file // entry recorded in meta-index file or such jar file is // missing in JRE. See bug 6340399. if (metaIndex == null) { ensureOpen(); } } }
Example #28
Source File: URLClassPath.java From hottub with GNU General Public License v2.0 | 5 votes |
JarLoader(URL url, URLStreamHandler jarHandler, HashMap<String, Loader> loaderMap) throws IOException { super(new URL("jar", "", -1, url + "!/", jarHandler)); csu = url; handler = jarHandler; lmap = loaderMap; if (!isOptimizable(url)) { ensureOpen(); } else { String fileName = url.getFile(); if (fileName != null) { fileName = ParseUtil.decode(fileName); File f = new File(fileName); metaIndex = MetaIndex.forJar(f); // If the meta index is found but the file is not // installed, set metaIndex to null. A typical // senario is charsets.jar which won't be installed // when the user is running in certain locale environment. // The side effect of null metaIndex will cause // ensureOpen get called so that IOException is thrown. if (metaIndex != null && !f.exists()) { metaIndex = null; } } // metaIndex is null when either there is no such jar file // entry recorded in meta-index file or such jar file is // missing in JRE. See bug 6340399. if (metaIndex == null) { ensureOpen(); } } }
Example #29
Source File: Handler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings("deprecation") protected void parseURL(URL url, String spec, int start, int limit) { String file = null; String ref = null; // first figure out if there is an anchor int refPos = spec.indexOf('#', limit); boolean refOnly = refPos == start; if (refPos > -1) { ref = spec.substring(refPos + 1, spec.length()); if (refOnly) { file = url.getFile(); } } // then figure out if the spec is // 1. absolute (jar:) // 2. relative (i.e. url + foo/bar/baz.ext) // 3. anchor-only (i.e. url + #foo), which we already did (refOnly) boolean absoluteSpec = false; if (spec.length() >= 4) { absoluteSpec = spec.substring(0, 4).equalsIgnoreCase("jar:"); } spec = spec.substring(start, limit); if (absoluteSpec) { file = parseAbsoluteSpec(spec); } else if (!refOnly) { file = parseContextSpec(url, spec); // Canonize the result after the bangslash int bangSlash = indexOfBangSlash(file); String toBangSlash = file.substring(0, bangSlash); String afterBangSlash = file.substring(bangSlash); sun.net.www.ParseUtil canonizer = new ParseUtil(); afterBangSlash = canonizer.canonizeString(afterBangSlash); file = toBangSlash + afterBangSlash; } setURL(url, "jar", "", -1, file, ref); }
Example #30
Source File: PolicyUtil.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static InputStream getInputStream(URL url) throws IOException { if ("file".equals(url.getProtocol())) { String path = url.getFile().replace('/', File.separatorChar); path = ParseUtil.decode(path); return new FileInputStream(path); } else { return url.openStream(); } }