Refine search
/** * Resolve the given resource URI to a {@code java.io.File}, * i.e. to a file in the file system. * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system * @since 2.5 */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { Assert.notNull(resourceUri, "Resource URI must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException( description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }
new File(URI) Paths.get(URI) new File(URI.getSchemeSpecificPart()) file:///C:/Program%20Files C:\Program Files C:\Program Files C:\Program Files file:/C:/Program%20Files C:\Program Files C:\Program Files C:\Program Files file:///C:/main.c++ C:\main.c++ C:\main.c++ C:\main.c++ file://VBOXSVR/Downloads/ IllegalArgumentException \\VBOXSVR\Downloads\ \\VBOXSVR\Downloads file:////VBOXSVR/Downloads/ \\VBOXSVR\Downloads \\VBOXSVR\Downloads\ \\VBOXSVR\Downloads file://///VBOXSVR/Downloads \\VBOXSVR\Downloads \\VBOXSVR\Downloads\ \\VBOXSVR\Downloads file://%3f/C:/Windows/ IllegalArgumentException IllegalArgumentException \\?\C:\Windows file:////%3F/C:/Windows/ \\?\C:\Windows InvalidPathException \\?\C:\Windows
/** * Determine if a uri is in origin-form according to * <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; }
public static File getClasspathFile(String file) throws FileNotFoundException { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); } catch (Throwable ex) { // } if (cl == null) { cl = TestUtils.class.getClassLoader(); } URL resourceUrl = cl.getResource(file); try { return new File(new URI(resourceUrl.toString()).getSchemeSpecificPart()); } catch (URISyntaxException e) { throw new FileNotFoundException(file); } }
String scheme = uri.getScheme(); String path = uri.getSchemeSpecificPart(); File relativeFile = new File(path); absoluteLocation = absoluteURI.getSchemeSpecificPart(); } else { absoluteLocation = scheme + ':' + absoluteURI.getSchemeSpecificPart(); URI newURI = new URI(absoluteLocation); ZipFile zipFile = new ZipFile(new File(newURI)); ZipEntry entry = zipFile.getEntry(file); if (entry != null) {
/** * Mangle given local java keystore file URI to allow use as a * LocalJavaKeyStoreProvider. * @param localFile absolute URI with file scheme and no authority component. * i.e. return of File.toURI, * e.g. file:///home/larry/creds.jceks * @return URI of the form localjceks://file/home/larry/creds.jceks * @throws IllegalArgumentException if localFile isn't not a file uri or if it * has an authority component. * @throws URISyntaxException if the wrapping process violates RFC 2396 */ public static URI nestURIForLocalJavaKeyStoreProvider(final URI localFile) throws URISyntaxException { if (!("file".equals(localFile.getScheme()))) { throw new IllegalArgumentException("passed URI had a scheme other than " + "file."); } if (localFile.getAuthority() != null) { throw new IllegalArgumentException("passed URI must not have an " + "authority component. For non-local keystores, please use " + JavaKeyStoreProvider.class.getName()); } return new URI(LocalJavaKeyStoreProvider.SCHEME_NAME, "//file" + localFile.getSchemeSpecificPart(), localFile.getFragment()); }
/** * Strip a URI of its scheme element. * * @param uri The URI whose scheme value should be stripped. * @return The stripped URI value. * @throws java.net.URISyntaxException */ public static URI stripScheme(URI uri) throws URISyntaxException { return new URI(stripPrefix(uri.getSchemeSpecificPart().trim(), "//")); }
/** * Resolve the given resource URL to a {@code java.io.File}, * i.e. to a file in the file system. * @param resourceUrl the resource URL to resolve * @param description a description of the original resource that * the URL was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URL resourceUrl, String description) throws FileNotFoundException { Assert.notNull(resourceUrl, "Resource URL must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) { throw new FileNotFoundException( description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUrl); } try { return new File(toURI(resourceUrl).getSchemeSpecificPart()); } catch (URISyntaxException ex) { // Fallback for URLs that are not valid URIs (should hardly ever happen). return new File(resourceUrl.getFile()); } }
/** * Resolve the given resource URI to a {@code java.io.File}, * i.e. to a file in the file system. * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system * @since 2.5 */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { Assert.notNull(resourceUri, "Resource URI must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException( description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }
URI uri = new URI(url.toString().replaceAll(" ", "%20")); return new File(uri.getSchemeSpecificPart()); } catch (URISyntaxException e) { return new File(url.getFile());
if ("hadoop".equals(uri.getScheme())) { try { hadoopUri = new URI(uri.getSchemeSpecificPart()); } catch (final URISyntaxException e) { throw new IOException("Not a valid hadoop URI: " + uri); switch (hadoopUri.getScheme()) { case "file": log.debug("Checking local path exists: {}", hadoopUri); return new File(hadoopUri).exists(); throw new IOException("Not a supported scheme: " + hadoopUri.getScheme());
/** * @param scheme the scheme string of the URI * @param authority the Authority of the URI * @param path the path component of the URI * @param query the query component of the URI */ public StandardURI(String scheme, Authority authority, String path, String query) { try { // Use java.net.URI to parse the URI components. java.net.URI uri; if (AlluxioURI.CUR_DIR.equals(path)) { uri = new java.net.URI(scheme, authority.toString().equals("") ? null : authority.toString(), AlluxioURI.normalizePath(path), query, null); } else { uri = new java.net.URI(scheme, authority.toString().equals("") ? null : authority.toString(), AlluxioURI.normalizePath(path), query, null).normalize(); } mScheme = uri.getScheme(); mSchemeSpecificPart = uri.getSchemeSpecificPart(); mAuthority = authority; mPath = uri.getPath(); mQuery = uri.getQuery(); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
/** * Strip a URI of its scheme element. * * @param uri * The URI whose scheme value should be stripped. * * @return The stripped URI value. * @throws URISyntaxException */ public static URI stripScheme(URI uri) throws URISyntaxException { return new URI(stripPrefix(uri.getSchemeSpecificPart().trim(), "//")); }
/** * Determine if a uri is in asterisk-form according to * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ public static boolean isAsteriskForm(URI uri) { return "*".equals(uri.getPath()) && uri.getScheme() == null && uri.getSchemeSpecificPart() == null && uri.getHost() == null && uri.getAuthority() == null && uri.getQuery() == null && uri.getFragment() == null; }
private static File getFileByURL(URL fileUrl) throws FileNotFoundException { Validate.notNull(fileUrl, "Resource URL must not be null"); if (!URL_PROTOCOL_FILE.equals(fileUrl.getProtocol())) { throw new FileNotFoundException("URL cannot be resolved to absolute file path " + "because it does not reside in the file system: " + fileUrl); } try { return new File(toURI(fileUrl.toString()).getSchemeSpecificPart()); } catch (URISyntaxException ex) { // NOSONAR // Fallback for URLs that are not valid URIs (should hardly ever happen). return new File(fileUrl.getFile()); } }
/** * Resolve the given resource URI to a {@code java.io.File}, * i.e. to a file in the file system. * * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { Assert.notNull(resourceUri, "Resource URI must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException( description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri ); } return new File(resourceUri.getSchemeSpecificPart()); }
private static File getFile(URL url) { try { return new File(new URI(url.toExternalForm()).getSchemeSpecificPart()); } catch (URISyntaxException e) { LOG.debug("Cannot translate URL to file name, expect a performance impact", e); return null; } }
/** * Set the concrete URI. * * @param uri the concrete URI (must not be {@code null}) * @return this builder */ public Builder setUri(final URI uri) { Assert.checkNotNullParam("uri", uri); final String fragment = uri.getFragment(); if (fragment != null && ! fragment.isEmpty()) { throw new IllegalArgumentException("Service URI " + uri + " may not have a fragment"); } if (! uri.isAbsolute()) { throw new IllegalArgumentException("Service URI " + uri + " must be absolute"); } final String query = uri.getQuery(); // sanitized URI try { this.uri = uri.isOpaque() ? new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null) : new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query != null && query.isEmpty() ? null : query, null); } catch (URISyntaxException e) { // should be impossible as the original URI was valid throw new IllegalStateException(e); } return this; }
/** Make sure that a path specifies a FileSystem. */ @Override public Path makeQualified(Path path) { Path fqPath = fs.makeQualified(path); // swap in our scheme if the filtered fs is using a different scheme if (swapScheme != null) { try { // NOTE: should deal with authority, but too much other stuff is broken fqPath = new Path( new URI(swapScheme, fqPath.toUri().getSchemeSpecificPart(), null) ); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } return fqPath; }
protected static Text getDtService(URI uri) { Text service; // remove fragment for forward compatibility with logical naming. final String fragment = uri.getFragment(); if (fragment != null) { service = new Text( uri.getScheme() + ":" + uri.getSchemeSpecificPart()); } else { service = new Text(uri.toString()); } return service; }