@Override public Iterable<Path> getRootDirectories() { return delegate.getRootDirectories(); }
private static Path buildRootPath() { Path root = Iterables.getFirst(FileSystems.getDefault().getRootDirectories(), null); if (root == null) { throw new RuntimeException("Can't find a root filesystem!"); } return root; }
private static Path root() { return FS.getRootDirectories().iterator().next(); }
private void setCurrentDirectoryRoot() { currentPath = null; loadDirectoryContents(StreamSupport.stream(FileSystems.getDefault().getRootDirectories().spliterator(), true)); }
private ImmutableList<ProfileFileElement> loadProfileFiles(Multimap<Path, String> pathsToAttempt) throws IOException { ImmutableList.Builder<ProfileFileElement> result = ImmutableList.builder(); try (Closer closer = Closer.create()) { for (Map.Entry<Path, Collection<String>> entry : pathsToAttempt.asMap().entrySet()) { Path base = entry.getKey(); if (Files.isRegularFile(base)) { FileSystem sourceFs = FileSystems.newFileSystem(base, getClass().getClassLoader()); closer.register(sourceFs); base = getOnlyElement(sourceFs.getRootDirectories()); } for (String path : entry.getValue()) { ProfileFileElement element = loadProfileFile(base, path); if (element != null) result.add(element); } } } return result.build(); }
public Schema load() throws IOException { if (sources.isEmpty()) { throw new IllegalStateException("No sources added."); } try (Closer closer = Closer.create()) { // Map the physical path to the file system root. For regular directories the key and the // value are equal. For ZIP files the key is the path to the .zip, and the value is the root // of the file system within it. Map<Path, Path> directories = new LinkedHashMap<>(); for (Path source : sources) { if (Files.isRegularFile(source)) { FileSystem sourceFs = FileSystems.newFileSystem(source, getClass().getClassLoader()); closer.register(sourceFs); directories.put(source, getOnlyElement(sourceFs.getRootDirectories())); } else { directories.put(source, source); } } return loadFromDirectories(directories); } }
private static void createAndInstallTempFolderForOutput( ErrorProneInMemoryFileManager fileManager) { Path tempDirectory; try { tempDirectory = Files.createTempDirectory( fileManager.fileSystem().getRootDirectories().iterator().next(), ""); } catch (IOException e) { throw new UncheckedIOException(e); } Arrays.stream(StandardLocation.values()) .filter(StandardLocation::isOutputLocation) .forEach( outputLocation -> { try { fileManager.setLocationFromPaths(outputLocation, ImmutableList.of(tempDirectory)); } catch (IOException e) { throw new UncheckedIOException(e); } }); }
if (Files.isRegularFile(oldChunkZipPath)) { try (FileSystem oldZip = FileSystems.newFileSystem(oldChunkZipPath, null)) { for (Path root : oldZip.getRootDirectories()) { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override
@Test public void testGetters() throws IOException { try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { assertThat(fs.isOpen()).isTrue(); assertThat(fs.isReadOnly()).isFalse(); assertThat(fs.getRootDirectories()).containsExactly(fs.getPath("/")); assertThat(fs.getFileStores()).isEmpty(); assertThat(fs.getSeparator()).isEqualTo("/"); assertThat(fs.supportedFileAttributeViews()).containsExactly("basic", "gcs"); } }
assertTrue(immutability.test(file.toURI())); assertTrue(immutability.test(file.toURI().toURL())); assertTrue(immutability.test(FileSystems.getDefault().getRootDirectories().iterator().next())); assertTrue(immutability.test(new AllPermission()));
@Override public Iterable<Path> getRootDirectories() { return delegate.getRootDirectories(); }
private static Path buildRootPath() { Path root = Iterables.getFirst(FileSystems.getDefault().getRootDirectories(), null); if (root == null) { throw new RuntimeException("Can't find a root filesystem!"); } return root; }
public static void main(String[] args) throws IOException { Path path = Paths.get("/tmp/testing"); FileSystem fs = FileSystems.newFileSystem(path, PerspectiveDataCopier.class.getClassLoader()); fs.getRootDirectories().forEach(root -> { try { Files.list(root).forEach(System.out::println); } catch (IOException e) { e.printStackTrace(); } }); } }
private static List<Path> getJrtFs() throws IOException { // http://openjdk.java.net/jeps/220 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); List<Path> classpath = new ArrayList<>(); for (Path root : fs.getRootDirectories()) { Files.list(root.resolve("modules")).forEach(classpath::add); } // technically, this leaks open FileSystem instance // which is okay, since singleton #instance is never released return classpath; }
public Path resolveAgainst(FileSystem fs) throws /*unchecked*/ InvalidPathException { String sep = fs.getSeparator(); Path root = fs.getRootDirectories().iterator().next(); return root.resolve(path.replace("/", sep)); }
private static List<Path> getJrtFs() throws IOException { // http://openjdk.java.net/jeps/220 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); List<Path> classpath = new ArrayList<>(); for (Path root : fs.getRootDirectories()) { Files.list(root.resolve("modules")).forEach(classpath::add); } // technically, this leaks open FileSystem instance // which is okay, since singleton #instance is never released return classpath; }
public static void unzip(Path zipFile, Path targetDir) throws IOException { if(!Files.exists(targetDir)) { Files.createDirectories(targetDir); } try (FileSystem zipfs = newFileSystem(zipFile)) { for (Path zipRoot : zipfs.getRootDirectories()) { copyFromZip(zipRoot, targetDir); } } }
/** * Creates the in-memory file system as specified. */ public FileSystem build() throws IOException { FileSystem fileSystem = Jimfs.newFileSystem(config.build()); createContent(Iterables.getOnlyElement(fileSystem.getRootDirectories())); return fileSystem; }
@Test public final void testNonexistent0() throws Exception { try (final FileSystem fs = this.getFileSystem()) { final Path root = fs.getRootDirectories().iterator().next(); final CatalogDisk disk = CatalogFilesystemReader.newDisk( new CatalogDiskName("test"), new CatalogDiskID(BigInteger.ZERO), root); final Optional<CatalogNodeType> r = disk.getNodeForPath(Arrays.asList("nonexistent", "other")); Assert.assertFalse(r.isPresent()); } }
@Test public void rootDirectories() { final Iterable<Path> paths = fileSystem.getRootDirectories(); int count = 0; for (final Path path : paths) { count++; Assert.assertEquals("Root was not in expected form", ArchivePaths.root().get(), path.toString()); } Assert.assertEquals("Should only be one root path per FS", 1, count); }