getSchemeSpecificPart ( )源码实例Demo

java.net.URI#getSchemeSpecificPart ( )源码实例Demo

下面列出了java.net.URI#getSchemeSpecificPart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bats   文件: Sources.java
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();
}
 
源代码2 项目: TrackRay   文件: WebApplication.java
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));
		}
	}
}
 
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;
    }
}
 
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;
}
 
源代码5 项目: juddi   文件: ApplicationConfigurationTest.java
@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);
	
}
 
源代码6 项目: tac   文件: LancherTest.java
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));
}
 
源代码7 项目: cucumber-performance   文件: URIPath.java
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);
    }
}
 
源代码8 项目: openjdk-jdk9   文件: ZipFileSystemProvider.java
@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));
}
 
private URI _getSpecURI(String spec) {
    URI specURI = URI.create(spec);

    if (_scheme.indexOf(':') == -1) {
        return specURI;
    }
    
    String schemeSpecificPart = specURI.getSchemeSpecificPart();
    return URI.create(schemeSpecificPart);
}
 
private String schemeSpecificPart(URI uri) {
	String part = uri.getSchemeSpecificPart();
	if (StringUtils.isEmpty(part)) {
		return part;
	}
	return part.startsWith("//") ? part.substring(2) : part;
}
 
源代码11 项目: jdk8u_jdk   文件: FaultyFileSystem.java
@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)));
}
 
源代码12 项目: openjdk-8-source   文件: ZipFileSystemProvider.java
@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));
}
 
源代码13 项目: jdk8u60   文件: FaultyFileSystem.java
@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)));
}
 
源代码14 项目: Smack   文件: FileUtils.java
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();
}
 
源代码15 项目: arthas   文件: CustomJavaFileObject.java
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
}
 
源代码16 项目: tomee   文件: MulticastConnectionFactory.java
protected static URI unwrap(final URI uri) throws URISyntaxException {
    return new URI(uri.getSchemeSpecificPart());
}
 
源代码17 项目: caja   文件: FileSystemUriPolicy.java
/** 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);
}
 
源代码18 项目: netty-4.1.22   文件: HttpUtil.java
/**
 * 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;
}
 
源代码19 项目: beakerx   文件: ResourceLoaderTest.java
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();
}
 
源代码20 项目: openjdk-jdk9   文件: PathFileObject.java
/**
 * 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

}