Java Code Examples for java.net.URI#getSchemeSpecificPart()
The following examples show how to use
java.net.URI#getSchemeSpecificPart() .
These examples are extracted from open source projects.
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 Project: Bats File: Sources.java License: Apache License 2.0 | 6 votes |
private File urlToFile(URL url) { if (!"file".equals(url.getProtocol())) { return null; } URI uri; try { uri = url.toURI(); } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to convert URL " + url + " to URI", e); } if (uri.isOpaque()) { // It is like file:test%20file.c++ // getSchemeSpecificPart would return "test file.c++" return new File(uri.getSchemeSpecificPart()); } // See https://stackoverflow.com/a/17870390/1261287 return Paths.get(uri).toFile(); }
Example 2
Source Project: TrackRay File: WebApplication.java License: GNU General Public License v3.0 | 6 votes |
protected static Archive createArchive(Class clazz) throws Exception { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URI location = codeSource != null ? codeSource.getLocation().toURI() : null; String path = location != null ? location.getSchemeSpecificPart() : null; if (path == null) { throw new IllegalStateException("Unable to determine code source archive"); } else { File root = new File(path); if (!root.exists()) { throw new IllegalStateException("Unable to determine code source archive from " + root); } else { return (Archive)(root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root)); } } }
Example 3
Source Project: marklogic-contentpump File: SingleDocumentWriter.java License: Apache License 2.0 | 6 votes |
protected static String getPathFromURI(DocumentURI uri) { String uriStr = uri.getUri(); try { URI child = new URI(uriStr); String childPath; if (child.isOpaque()) { childPath = child.getSchemeSpecificPart(); } else { childPath = child.getPath(); } return childPath; } catch (Exception ex) { LOG.error("Error parsing URI " + uriStr + "."); return uriStr; } }
Example 4
Source Project: openhab-core File: ThingConfigDescriptionAliasProvider.java License: Eclipse Public License 2.0 | 6 votes |
private @Nullable URI getThingConfigDescriptionURI(URI uri) { // First, get the thing type so we get the generic config descriptions ThingUID thingUID = new ThingUID(uri.getSchemeSpecificPart()); Thing thing = thingRegistry.get(thingUID); if (thing == null) { return null; } ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID()); if (thingType == null) { return null; } // Get the config description URI for this thing type URI configURI = thingType.getConfigDescriptionURI(); return configURI; }
Example 5
Source Project: juddi File: ApplicationConfigurationTest.java License: Apache License 2.0 | 6 votes |
@Test public void testURLFormats() throws MalformedURLException, URISyntaxException { URI file = new URI("file:/tmp/"); String path = file.getSchemeSpecificPart(); Assert.assertEquals("/tmp/", path); URI fileInJar = new URI("jar:file:/tmp/my.jar!/"); String path1 = fileInJar.getSchemeSpecificPart(); Assert.assertEquals("file:/tmp/my.jar!/", path1); URI fileInZip = new URI("zip:D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!"); String path2 = fileInZip.getSchemeSpecificPart(); Assert.assertEquals("D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!", path2); URI fileInVfszip = new URI("vfsfile:/tmp/SOA%20Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml"); String path3 = fileInVfszip.getSchemeSpecificPart(); Assert.assertEquals("/tmp/SOA Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml", path3); }
Example 6
Source Project: tac File: LancherTest.java License: MIT License | 6 votes |
protected final Archive createArchive() throws Exception { ProtectionDomain protectionDomain = getClass().getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URI location = (codeSource == null ? null : codeSource.getLocation().toURI()); String path = (location == null ? null : location.getSchemeSpecificPart()); if (path == null) { throw new IllegalStateException("Unable to determine code source archive"); } File root = new File(path); if (!root.exists()) { throw new IllegalStateException( "Unable to determine code source archive from " + root); } return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root)); }
Example 7
Source Project: cucumber-performance File: URIPath.java License: MIT License | 5 votes |
private static URI parseAssumeFileScheme(String pathIdentifier) { File pathFile = new File(pathIdentifier); if (pathFile.isAbsolute()) { return pathFile.toURI(); } try { URI root = new File("").toURI(); URI relative = root.relativize(pathFile.toURI()); // Scheme is lost by relativize return new URI("file", relative.getSchemeSpecificPart(), relative.getFragment()); } catch (URISyntaxException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
Example 8
Source Project: openjdk-jdk9 File: ZipFileSystemProvider.java License: GNU General Public License v2.0 | 5 votes |
@Override public Path getPath(URI uri) { String spec = uri.getSchemeSpecificPart(); int sep = spec.indexOf("!/"); if (sep == -1) throw new IllegalArgumentException("URI: " + uri + " does not contain path info ex. jar:file:/c:/foo.zip!/BAR"); return getFileSystem(uri).getPath(spec.substring(sep + 1)); }
Example 9
Source Project: spark-sdk-android File: WsURLStreamHandlerImpl.java License: Apache License 2.0 | 5 votes |
private URI _getSpecURI(String spec) { URI specURI = URI.create(spec); if (_scheme.indexOf(':') == -1) { return specURI; } String schemeSpecificPart = specURI.getSchemeSpecificPart(); return URI.create(schemeSpecificPart); }
Example 10
Source Project: spring-cloud-contract File: PactStubDownloaderBuilder.java License: Apache License 2.0 | 5 votes |
private String schemeSpecificPart(URI uri) { String part = uri.getSchemeSpecificPart(); if (StringUtils.isEmpty(part)) { return part; } return part.startsWith("//") ? part.substring(2) : part; }
Example 11
Source Project: jdk8u_jdk File: FaultyFileSystem.java License: GNU General Public License v2.0 | 5 votes |
@Override public Path getPath(URI uri) { checkScheme(uri); if (delegate == null) throw new FileSystemNotFoundException(); // only allow absolute path String path = uri.getSchemeSpecificPart(); if (! path.startsWith("///")) { throw new IllegalArgumentException(); } return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3))); }
Example 12
Source Project: openjdk-8-source File: ZipFileSystemProvider.java License: GNU General Public License v2.0 | 5 votes |
@Override public Path getPath(URI uri) { String spec = uri.getSchemeSpecificPart(); int sep = spec.indexOf("!/"); if (sep == -1) throw new IllegalArgumentException("URI: " + uri + " does not contain path info ex. jar:file:/c:/foo.zip!/BAR"); return getFileSystem(uri).getPath(spec.substring(sep + 1)); }
Example 13
Source Project: jdk8u60 File: FaultyFileSystem.java License: GNU General Public License v2.0 | 5 votes |
@Override public Path getPath(URI uri) { checkScheme(uri); if (delegate == null) throw new FileSystemNotFoundException(); // only allow absolute path String path = uri.getSchemeSpecificPart(); if (! path.startsWith("///")) { throw new IllegalArgumentException(); } return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3))); }
Example 14
Source Project: Smack File: FileUtils.java License: Apache License 2.0 | 5 votes |
public static InputStream getStreamForUri(URI uri, ClassLoader loader) throws IOException { String protocol = uri.getScheme(); if (protocol.equals("classpath")) { String path = uri.getSchemeSpecificPart(); return getStreamForClasspathFile(path, loader); } URL url = uri.toURL(); return url.openStream(); }
Example 15
Source Project: arthas File: CustomJavaFileObject.java License: Apache License 2.0 | 4 votes |
public CustomJavaFileObject(String binaryName, URI uri) { this.uri = uri; this.binaryName = binaryName; name = uri.getPath() == null ? uri.getSchemeSpecificPart() : uri.getPath(); // for FS based URI the path is not null, for JAR URI the scheme specific part is not null }
Example 16
Source Project: tomee File: MulticastConnectionFactory.java License: Apache License 2.0 | 4 votes |
protected static URI unwrap(final URI uri) throws URISyntaxException { return new URI(uri.getSchemeSpecificPart()); }
Example 17
Source Project: caja File: FileSystemUriPolicy.java License: Apache License 2.0 | 4 votes |
/** Return a new URI with a different fragment. */ private static URI refragUri(URI uri, String frag) throws URISyntaxException { return new URI(uri.getScheme(), uri.getSchemeSpecificPart(), frag); }
Example 18
Source Project: netty-4.1.22 File: HttpUtil.java License: Apache License 2.0 | 4 votes |
/** * Determine if a uri is in origin-form according to 根据rfc7230, 5.3确定uri是否为原始形式。 * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ public static boolean isOriginForm(URI uri) { return uri.getScheme() == null && uri.getSchemeSpecificPart() == null && uri.getHost() == null && uri.getAuthority() == null; }
Example 19
Source Project: beakerx File: ResourceLoaderTest.java License: Apache License 2.0 | 4 votes |
public static String getOsAppropriatePath(String fileName, Class clazz) throws Exception { URI uriToFile = clazz.getClassLoader().getResource(fileName).toURI(); return IS_WINDOWS ? uriToFile.getSchemeSpecificPart().substring(1) : uriToFile.getSchemeSpecificPart(); }
Example 20
Source Project: openjdk-jdk9 File: PathFileObject.java License: GNU General Public License v2.0 | 3 votes |
/** * Return the last component of a presumed hierarchical URI. * From the scheme specific part of the URI, it returns the substring * after the last "/" if any, or everything if no "/" is found. * @param fo the file object * @return the simple name of the file object */ public static String getSimpleName(FileObject fo) { URI uri = fo.toUri(); String s = uri.getSchemeSpecificPart(); return s.substring(s.lastIndexOf("/") + 1); // safe when / not found }