Refine search
private static void listFilesystems() { System.out.println("Installed filesystem providers:"); for (FileSystemProvider p : FileSystemProvider.installedProviders()) { System.out.println(" " + p.getScheme()); } }
private static void updateZip(File zip, File entry, String entryName) throws IOException { Map<String, String> env = new HashMap<>(); String uriPath = "jar:" + zip.toURI().toString(); URI uri = URI.create(uriPath); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { fs.provider().checkAccess(fs.getPath(entryName), AccessMode.READ); Path target = fs.getPath(entryName); Path source = entry.toPath(); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw e; } }
public static FileSystem openZip(Path in) throws IOException { for (FileSystemProvider p : FileSystemProvider.installedProviders()) { String s = p.getScheme(); if ("jar".equals(s) || "zip".equalsIgnoreCase(s)) { return p.newFileSystem(in, new HashMap<String, Object>()); } } throw new IOException("cant find zipfs support"); }
public void beginFileRead(String absolutePath) { Path path = fileSystem.getPath(absolutePath); try { inputStream = fileSystem.provider().newInputStream(path, StandardOpenOption.READ); } catch (IOException e) { logger.warn("File error ",e); inputStream = null; } }
@Test public void fileChannelCreateNew() throws Exception { Path test = fs.getPath("test.txt"); EnumSet<StandardOpenOption> options = EnumSet.<StandardOpenOption> of( StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE); fs.provider().newFileChannel(test, options); }
public static DirectoryStream newDirectoryStream(Path dir, String glob) throws IOException { FileSystem fs = dir.getFileSystem(); final PathMatcher matcher = fs.getPathMatcher("glob:" + glob); DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { public boolean accept(Path entry) { return matcher.matches(entry.getFileName()); } }; return fs.provider().newDirectoryStream(dir, filter); }
/** * Ensures configured directory {@code path} exists. * @throws IOException if {@code path} exists, but is not a directory, not accessible, or broken symbolic link. */ static void ensureDirectoryExists(Path path) throws IOException { // this isn't atomic, but neither is createDirectories. if (Files.isDirectory(path)) { // verify access, following links (throws exception if something is wrong) // we only check READ as a sanity test path.getFileSystem().provider().checkAccess(path.toRealPath(), AccessMode.READ); } else { // doesn't exist, or not a directory try { Files.createDirectories(path); } catch (FileAlreadyExistsException e) { // convert optional specific exception so the context is clear IOException e2 = new NotDirectoryException(path.toString()); e2.addSuppressed(e); throw e2; } } }
PosixFileAttributes readAttributes = nioPath .getFileSystem() .provider() .getFileAttributeView(nioPath, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).readAttributes();
/** * 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); } }
private static Path determineBaseDir(Path configPath) { Path baseDir = configPath.getParent(); if (baseDir == null && configPath.getFileSystem().provider().getScheme().equals("jar")) { baseDir = Iterables.getFirst(configPath.getFileSystem().getRootDirectories(), null); } if (baseDir == null) { throw new IllegalStateException("Cannot determine base dir given config resource: " + configPath); } return baseDir; }
@Override public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException { FileSystemProvider realProvider = path.getFileSystem().provider(); return realProvider.newFileSystem(path, env); }
@Test public void testWrongUriAtProviderNewFails() throws IOException { assertThatThrownBy( () -> FS.provider().newFileSystem( URI.create( FS.provider().getScheme() + "N:" ), Collections.EMPTY_MAP ) ). isInstanceOf( IllegalArgumentException.class ); }
private DirectoryStream<Path> directoryStream(Path dir) throws IOException { // create a matcher and return a filter that uses it. return dir.getFileSystem().provider().newDirectoryStream(dir, filter); } }
return new XnioFileChannel(path.getFileSystem().provider().newFileChannel(path, openOptions)); } catch (NoSuchFileException e) { throw new FileNotFoundException(e.getMessage());
public static InputStream getInputStream(URI uri) throws IOException, URISyntaxException { FileSystem fs = getFileSystem(uri); Path path = getPath(uri); return fs.provider().newInputStream(path); }
for (FileSystemProvider provider : FileSystemProvider.installedProviders()) { if ("jar".equals(provider.getScheme())) return provider.newFileSystem((new File(Start.class .getProtectionDomain().getCodeSource().getLocation().toURI())) .toPath(), new HashMap<String, Object>()); }
@Override public Path getPath(final URI uri) { return delegate.getPath(uri); }