return provider.getPath(uri);
return provider.getPath(uri);
@Override public Path getPath(final URI uri) { return delegate.getPath(uri); }
@Override public Path parsePath(URI uri) { return delegate.getPath(uri); }
/** * Returns a {@code Path} from a URI * <p> * This works just like {@code Paths.get()}. * <p> * Remember: this should almost never be used. Usually resolve * a path against an existing one! */ public static Path get(URI uri) { if (uri.getScheme().equalsIgnoreCase("file")) { return DEFAULT.provider().getPath(uri); } else { return Paths.get(uri); } }
@Override public Path getPath(final URI uri) {return wrapped().getPath(uri);}
/** * Returns a {@code Path} from a URI * <p> * This works just like {@code Paths.get()}. * <p> * Remember: this should almost never be used. Usually resolve * a path against an existing one! */ public static Path get(URI uri) { if (uri.getScheme().equalsIgnoreCase("file")) { return DEFAULT.provider().getPath(uri); } else { return Paths.get(uri); } }
/** * Returns a {@code Path} from a URI * <p> * This works just like {@code Paths.get()}. * <p> * Remember: this should almost never be used. Usually resolve * a path against an existing one! */ public static Path get(URI uri) { if (uri.getScheme().equalsIgnoreCase("file")) { return DEFAULT.provider().getPath(uri); } else { return Paths.get(uri); } }
/** * Returns a {@code Path} from a URI * <p> * This works just like {@code Paths.get()}. * <p> * Remember: this should almost never be used. Usually resolve * a path against an existing one! */ public static Path get(URI uri) { if (uri.getScheme().equalsIgnoreCase("file")) { return DEFAULT.provider().getPath(uri); } else { return Paths.get(uri); } }
/** * Returns a {@code Path} from a URI * <p> * This works just like {@code Paths.get()}. * <p> * Remember: this should almost never be used. Usually resolve * a path against an existing one! */ public static Path get(URI uri) { if (uri.getScheme().equalsIgnoreCase("file")) { return DEFAULT.provider().getPath(uri); } else { return Paths.get(uri); } }
/** * Convert the given path {@link URI} to a {@link Path} object. * @param uri the path to convert * @return a {@link Path} object */ public static Path asPath(URI uri) { try { return Paths.get(uri); } catch (FileSystemNotFoundException e) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { throw e; } try { return FileSystems.newFileSystem(uri, new HashMap<>(), cl).provider().getPath(uri); } catch (IOException ex) { throw new RuntimeException("Cannot create filesystem for " + uri, ex); } } }
private List<Path> locations() { return classpaths.stream().map(location -> { try { URI uri = getClass().getResource(location).toURI(); if (uri.getScheme().equals("jar")) { try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap())) { return fileSystem.provider().getPath(uri); } } else { return Paths.get(uri); } } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.toList()); } }
/** * Convert the given path {@link URI} to a {@link Path} object. * @param uri the path to convert * @return a {@link Path} object */ public static Path asPath(URI uri) { try { return Paths.get(uri); } catch (FileSystemNotFoundException e) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { throw e; } try { return FileSystems.newFileSystem(uri, new HashMap<>(), cl).provider().getPath(uri); } catch (IOException ex) { throw new RuntimeException("Cannot create filesystem for " + uri, ex); } } }
public static Path create( URI uri ) { try { return Paths.get( uri ); } catch( FileSystemNotFoundException nfe ) { try { Map<String, String> env = new HashMap<>(); env.put( "create", "true" ); // creates zip/jar file if not already exists FileSystem fs = FileSystems.newFileSystem( uri, env ); return fs.provider().getPath( uri ); } catch( IOException e ) { throw new RuntimeException( e ); } } }
public static Path create( URI uri ) { try { return Paths.get( uri ); } catch( FileSystemNotFoundException nfe ) { try { Map<String, String> env = new HashMap<>(); env.put( "create", "true" ); // creates zip/jar file if not already exists FileSystem fs = FileSystems.newFileSystem( uri, env ); return fs.provider().getPath( uri ); } catch( IOException e ) { throw new RuntimeException( e ); } } }
/** * Convert the given path {@link URI} to a {@link Path} object. * @param uri the path to convert * @return a {@link Path} object */ public static Path asPath(URI uri) { try { return Paths.get(uri); } catch (FileSystemNotFoundException e) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { throw e; } try { return FileSystems.newFileSystem(uri, new HashMap<>(), cl).provider().getPath(uri); } catch (IOException ex) { throw new RuntimeException("Cannot create filesystem for " + uri, ex); } } }
/** * Converts the given URI to a {@link Path} object. If the filesystem cannot be found in the usual way, then attempt * to load the filesystem provider using the thread context classloader. This is needed when the filesystem * provider is loaded using a URL classloader (e.g. in spark-submit). * * @param uriString the URI to convert * @return the resulting {@code Path} * @throws IOException an I/O error occurs creating the file system */ public static Path getPath(String uriString) throws IOException { URI uri = URI.create(uriString); try { // if the URI has no scheme, then treat as a local file, otherwise use the scheme to determine the filesystem to use return uri.getScheme() == null ? Paths.get(uriString) : Paths.get(uri); } catch (FileSystemNotFoundException e) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { throw e; } return FileSystems.newFileSystem(uri, new HashMap<>(), cl).provider().getPath(uri); } }
@Test public void testGetPathOtherURI() throws IOException { assertThatThrownBy( () -> FS.provider().getPath( otherProviderAbsA().toUri() ) ).isInstanceOf( IllegalArgumentException.class ); }
public static Path uriToBundlePath(Bundle bundle, URI uri) { URI rootUri = bundle.getRoot().toUri(); uri = relativizeFromBase(uri, rootUri); if (uri.isAbsolute() || uri.getFragment() != null) return null; return bundle.getFileSystem().provider().getPath(rootUri.resolve(uri)); }
private Path toDestination(Path path) { if (path.equals(source)) // Top-level folder return destination; // Path relativize = source.relativize(path); // return destination.resolve(relativize); /* * The above does not work as ZipPath throws ProviderMisMatchException * when given a relative filesystem Path */ URI rel = pathOnly(uriWithSlash(source)).relativize( pathOnly(path.toUri())); if (rel.isAbsolute()) throw new IllegalStateException("Can't relativize " + rel); URI dest = uriWithSlash(destination).resolve(rel); return destination.getFileSystem().provider().getPath(dest); }