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

The following are Jave code examples for showing how to use getSchemeSpecificPart() of the java.net.URI class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: UriToPath.java   View Source Code Vote up 6 votes
/**
 * Executes the task.
 */
public void execute() throws BuildException {
    try {
        final URI uri = new URI(uriString);
        
        String path = uri.getSchemeSpecificPart();
        while (path.startsWith("/")) { // NOI18N
            path = path.substring(1);
        }
        
        if (uri.getScheme().equals("file")) {
            path = "local/" + path;
        }
        path = path.replace(":", "_").replace("*", "_");
        getProject().setProperty(property, path);
    } catch (URISyntaxException e) {
        throw new BuildException("Cannot parse URI.",e); // NOI18N
    }
}
 
Example 2
Project: hadoop-oss   File: PathData.java   View Source Code Vote up 6 votes
private static String uriToString(URI uri, boolean inferredSchemeFromPath) {
  String scheme = uri.getScheme();
  // No interpretation of symbols. Just decode % escaped chars.
  String decodedRemainder = uri.getSchemeSpecificPart();

  // Drop the scheme if it was inferred to ensure fidelity between
  // the input and output path strings.
  if ((scheme == null) || (inferredSchemeFromPath)) {
    if (Path.isWindowsAbsolutePath(decodedRemainder, true)) {
      // Strip the leading '/' added in stringToUri so users see a valid
      // Windows path.
      decodedRemainder = decodedRemainder.substring(1);
    }
    return decodedRemainder;
  } else {
    StringBuilder buffer = new StringBuilder();
    buffer.append(scheme);
    buffer.append(":");
    buffer.append(decodedRemainder);
    return buffer.toString();
  }
}
 
Example 3
Project: incubator-netbeans   File: KeyRefImpl.java   View Source Code Vote up 5 votes
private String getLocalName(String uri) {
    String localName = null;
    try {
        URI u = new URI(uri);
        localName = u.getSchemeSpecificPart();
    } catch (URISyntaxException ex) {
    }
    return localName;
}
 
Example 4
Project: openjdk-jdk10   File: Locations.java   View Source Code Vote up 5 votes
private boolean contains(Collection<Path> searchPath, Path file) throws IOException {

        if (searchPath == null) {
            return false;
        }

        Path enclosingJar = null;
        if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) {
            URI uri = file.toUri();
            if (uri.getScheme().equals("jar")) {
                String ssp = uri.getSchemeSpecificPart();
                int sep = ssp.lastIndexOf("!");
                if (ssp.startsWith("file:") && sep > 0) {
                    enclosingJar = Paths.get(URI.create(ssp.substring(0, sep)));
                }
            }
        }

        Path nf = normalize(file);
        for (Path p : searchPath) {
            Path np = normalize(p);
            if (np.getFileSystem() == nf.getFileSystem()
                    && Files.isDirectory(np)
                    && nf.startsWith(np)) {
                return true;
            }
            if (enclosingJar != null
                    && Files.isSameFile(enclosingJar, np)) {
                return true;
            }
        }

        return false;
    }
 
Example 5
Project: openjdk-jdk10   File: ZipFileSystemProvider.java   View Source Code Vote up 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 6
Project: truevfs   File: TUriHelper.java   View Source Code Vote up 5 votes
/**
 * Eventually recreates the given URI to work around
 * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7198297">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7198297</a>:
 * <pre>
 * {@code assert null == new URI("x/").resolve("..").getSchemeSpecificPart();}
 * </pre>
 *
 * @param  uri the URI to fix.
 * @return A fixed URI or {@code uri} if it doesn't need fixing.
 */
static URI fix(final URI uri) {
    final String ssp = uri.getSchemeSpecificPart();
    final String a = uri.getAuthority();
    // Workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7198297 :
    // assert null == new URI("foo/").resolve(new URI("..")).getRawSchemeSpecificPart();
    if (null == ssp
            || null == a && ssp.startsWith(SEPARATOR + SEPARATOR)) // empty authority
        return new UriBuilder(uri).toUri();
    return uri;
}
 
Example 7
Project: joai-project   File: NormalizedURL.java   View Source Code Vote up 5 votes
public void normalizePercentEncoding() {
    try {
        uri = new URI(uri.getScheme(), 
                      uri.getSchemeSpecificPart(), 
                      uri.getFragment());
    } catch (URISyntaxException e) {
        // This should never be reached
        e.printStackTrace();
    }
}
 
Example 8
Project: jdk8u-jdk   File: FaultyFileSystem.java   View Source Code Vote up 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 9
Project: mi-firma-android   File: AOUtil.java   View Source Code Vote up 5 votes
/** Obtiene el flujo de entrada de un fichero (para su lectura) a partir de su URI.
 * @param uri URI del fichero a leer
 * @return Flujo de entrada hacia el contenido del fichero
 * @throws IOException Cuando no se ha podido abrir el fichero de datos. */
public static InputStream loadFile(final URI uri) throws IOException {

    if (uri == null) {
        throw new IllegalArgumentException("Se ha pedido el contenido de una URI nula"); //$NON-NLS-1$
    }

    if (uri.getScheme().equals("file")) { //$NON-NLS-1$
        // Es un fichero en disco. Las URL de Java no soportan file://, con
        // lo que hay que diferenciarlo a mano

        // Retiramos el "file://" de la uri
        String path = uri.getSchemeSpecificPart();
        if (path.startsWith("//")) { //$NON-NLS-1$
            path = path.substring(2);
        }
        return new FileInputStream(new File(path));
    }

    // Es una URL
    final InputStream tmpStream = new BufferedInputStream(uri.toURL().openStream());

    // Las firmas via URL fallan en la descarga por temas de Sun, asi que
    // descargamos primero
    // y devolvemos un Stream contra un array de bytes
    final byte[] tmpBuffer = getDataFromInputStream(tmpStream);

    return new java.io.ByteArrayInputStream(tmpBuffer);
}
 
Example 10
Project: openjdk-jdk10   File: FaultyFileSystem.java   View Source Code Vote up 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 11
Project: xlight_android_native   File: SseURLStreamHandlerImpl.java   View Source Code Vote up 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 12
Project: javaide   File: BaseFileObject.java   View Source Code Vote up 5 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.
 */
public static String getSimpleName(FileObject fo) {
    URI uri = fo.toUri();
    String s = uri.getSchemeSpecificPart();
    return s.substring(s.lastIndexOf("/") + 1); // safe when / not found

}
 
Example 13
Project: freecol   File: FontResource.java   View Source Code Vote up 5 votes
/**
 * Do not use directly.
 *
 * @param resourceLocator The {@code URI} used when loading this
 *     resource.
 * @exception IOException if unable to read the font.
 */
public FontResource(URI resourceLocator) throws IOException {
    super(resourceLocator);
    font = null;
    try {
        if (resourceLocator.getPath() != null
            && resourceLocator.getPath().endsWith(".ttf")) {
            URL url = resourceLocator.toURL();
            font = Font.createFont(Font.TRUETYPE_FONT, url.openStream());
        } else {
            String name = resourceLocator.getSchemeSpecificPart();
            font = Font.decode(name.substring(SCHEME.length()));
        }

        if (font != null) {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .registerFont(font);
        }

        logger.info("Loaded font: " + font.getFontName()
            + " from: " + resourceLocator);
    } catch (FontFormatException|IOException ex) {
        logger.log(Level.WARNING,
            "Failed loading font from: " + resourceLocator, ex);
        throw new IOException(ex.getMessage());
    }
}
 
Example 14
Project: jdk8u-jdk   File: ZipFileSystemProvider.java   View Source Code Vote up 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 15
Project: OpenJSharp   File: BaseFileObject.java   View Source Code Vote up 5 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.
 */
public static String getSimpleName(FileObject fo) {
    URI uri = fo.toUri();
    String s = uri.getSchemeSpecificPart();
    return s.substring(s.lastIndexOf("/") + 1); // safe when / not found

}
 
Example 16
Project: OpenJSharp   File: ZipFileSystemProvider.java   View Source Code Vote up 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 17
Project: java-9-wtf   File: MavenCatalogResolver.java   View Source Code Vote up 4 votes
@Override
public String getResolvedEntity(String publicId, String systemId) {
	getLog().debug(
			MessageFormat.format(
					"Resolving publicId [{0}], systemId [{1}].", publicId,
					systemId));
	final String superResolvedEntity = super.getResolvedEntity(publicId,
			systemId);
	getLog().debug(
			MessageFormat
					.format("Parent resolver has resolved publicId [{0}], systemId [{1}] to [{2}].",
							publicId, systemId, superResolvedEntity));
	if (superResolvedEntity != null) {
		systemId = superResolvedEntity;
	}

	if (systemId == null) {
		return null;
	}

	try {
		final URI uri = new URI(systemId);
		if (URI_SCHEME_MAVEN.equals(uri.getScheme())) {
			getLog().debug(
					MessageFormat
							.format("Resolving systemId [{1}] as Maven dependency resource.",
									publicId, systemId));
			final String schemeSpecificPart = uri.getSchemeSpecificPart();
			try {
				final DependencyResource dependencyResource = DependencyResource
						.valueOf(schemeSpecificPart);
				try {
					final URL url = dependencyResourceResolver
							.resolveDependencyResource(dependencyResource);
					String resolved = url.toString();
					getLog().debug(
							MessageFormat.format(
									"Resolved systemId [{1}] to [{2}].",
									publicId, systemId, resolved));
					return resolved;
				} catch (Exception ex) {
					getLog().error(
							MessageFormat
									.format("Error resolving dependency resource [{0}].",
											dependencyResource));
				}
			} catch (IllegalArgumentException iaex) {
				getLog().error(
						MessageFormat
								.format("Error parsing dependency descriptor [{0}].",
										schemeSpecificPart));

			}
			getLog().error(
					MessageFormat
							.format("Failed to resolve systemId [{1}] as dependency resource. "
											+ "Returning parent resolver result [{2}].",
									publicId, systemId, superResolvedEntity));
			return superResolvedEntity;
		} else {
			getLog().debug(
					MessageFormat
							.format("SystemId [{1}] is not a Maven dependency resource URI. "
											+ "Returning parent resolver result [{2}].",
									publicId, systemId, superResolvedEntity));
			return superResolvedEntity;
		}
	} catch (URISyntaxException urisex) {
		getLog().debug(
				MessageFormat
						.format("Coul not parse the systemId [{1}] as URI. "
										+ "Returning parent resolver result [{2}].",
								publicId, systemId, superResolvedEntity));
		return superResolvedEntity;
	}
}
 
Example 18
Project: beaker-notebook-archive   File: CsvPlotReaderTest.java   View Source Code Vote up 4 votes
private String getOsAppropriatePath(String fileName) throws Exception {
  URI uriToFile = getClass().getClassLoader().getResource(fileName).toURI();
  return IS_WINDOWS
      ? uriToFile.getSchemeSpecificPart().substring(1)
      : uriToFile.getSchemeSpecificPart();
}
 
Example 19
Project: beaker-notebook-archive   File: ResourceLoaderTest.java   View Source Code Vote up 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
Project: athena   File: IsisRouterId.java   View Source Code Vote up 2 votes
/**
 * Creates ISIS router id instance from the URI.
 *
 * @param uri device URI
 * @return ISIS router id instance
 */
public static IsisRouterId isisRouterId(URI uri) {
    checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme");
    return new IsisRouterId(uri.getSchemeSpecificPart());
}