Java Code Examples for java.net.URI#getSchemeSpecificPart()

The following examples show how to use java.net.URI#getSchemeSpecificPart() . 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: Sources.java    From Bats with Apache License 2.0 6 votes vote down vote up
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 File: LancherTest.java    From tac with MIT License 6 votes vote down vote up
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 3
Source File: WebApplication.java    From TrackRay with GNU General Public License v3.0 6 votes vote down vote up
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 4
Source File: SingleDocumentWriter.java    From marklogic-contentpump with Apache License 2.0 6 votes vote down vote up
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 5
Source File: ThingConfigDescriptionAliasProvider.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
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 6
Source File: ApplicationConfigurationTest.java    From juddi with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: WsURLStreamHandlerImpl.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
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 8
Source File: FileUtils.java    From Smack with Apache License 2.0 5 votes vote down vote up
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 9
Source File: FaultyFileSystem.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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 10
Source File: ZipFileSystemProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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 11
Source File: FaultyFileSystem.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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 File: PactStubDownloaderBuilder.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
private String schemeSpecificPart(URI uri) {
	String part = uri.getSchemeSpecificPart();
	if (StringUtils.isEmpty(part)) {
		return part;
	}
	return part.startsWith("//") ? part.substring(2) : part;
}
 
Example 13
Source File: URIPath.java    From cucumber-performance with MIT License 5 votes vote down vote up
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 14
Source File: ZipFileSystemProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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 15
Source File: HttpUtil.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: ResourceLoaderTest.java    From beakerx with Apache License 2.0 4 votes vote down vote up
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 17
Source File: FileSystemUriPolicy.java    From caja with Apache License 2.0 4 votes vote down vote up
/** 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 File: MulticastConnectionFactory.java    From tomee with Apache License 2.0 4 votes vote down vote up
protected static URI unwrap(final URI uri) throws URISyntaxException {
    return new URI(uri.getSchemeSpecificPart());
}
 
Example 19
Source File: CustomJavaFileObject.java    From arthas with Apache License 2.0 4 votes vote down vote up
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 20
Source File: PathFileObject.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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

}