@Override public Iterable<FileStore> getFileStores() { return delegate.getFileStores(); }
static FileStore getFileStore(Path path) throws IOException { FileStore store = Files.getFileStore(path); String mount = getMountPoint(store); // find the "matching" FileStore from system list, it's the one we want, but only return // that if it's unambiguous (only one matching): FileStore sameMountPoint = null; for (FileStore fs : path.getFileSystem().getFileStores()) { if (mount.equals(getMountPoint(fs))) { if (sameMountPoint == null) { sameMountPoint = fs; } else { // more than one filesystem has the same mount point; something is wrong! // fall back to crappy one we got from Files.getFileStore return store; } } } if (sameMountPoint != null) { // ok, we found only one, use it: return sameMountPoint; } else { // fall back to crappy one we got from Files.getFileStore return store; } }
@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"); } }
@Override public Iterable<FileStore> getFileStores() { return delegate.getFileStores(); }
@Override public Iterable<FileStore> getFileStores() { return rootFs.getFileStores(); }
/** * {@inheritDoc} * * @see java.nio.file.spi.FileSystemProvider#getFileStore(java.nio.file.Path) */ @Override public FileStore getFileStore(final Path path) throws IOException { final FileStore fileStore = path.getFileSystem().getFileStores().iterator().next(); return fileStore; }
/** * {@inheritDoc} * * @see java.nio.file.spi.FileSystemProvider#getFileStore(java.nio.file.Path) */ @Override public FileStore getFileStore(final Path path) throws IOException { final FileStore fileStore = path.getFileSystem().getFileStores().iterator().next(); return fileStore; }
@Override public Iterable<FileStore> getFileStores() { List<FileStore> stores = new ArrayList<>(); for ( String key : drives.keySet() ) { stores.add( drives.get(key).getFileStores().iterator().next()); } return stores; }
import java.io.IOException; import java.nio.file.FileStore; import java.nio.file.FileSystems; public class TestFileStore { public static void main(String[] args) throws IOException { for (FileStore fileStore : FileSystems.getDefault().getFileStores()) { System.out.println(fileStore.name()); System.out.println("Unallocated space: " + fileStore.getUnallocatedSpace()); System.out.println("Unused space: " + fileStore.getUsableSpace()); System.out.println("************************************"); } } }
protected BundleFileStore getFileStore() { // We assume there's only one file store, as is true for ZipProvider return new BundleFileStore(this, getOrigFS().getFileStores().iterator() .next()); }
@Test @Category( FileStores.class ) public void testFileStoreIterable() { assertThat( FS.getFileStores() ).isNotEmpty(); }
import java.io.IOException; import java.nio.file.FileStore; import java.nio.file.FileSystems; public class ListMountedVolumesWithNio { public static void main(String[] args) throws IOException { for (FileStore store : FileSystems.getDefault().getFileStores()) { long total = store.getTotalSpace() / 1024; long used = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024; long avail = store.getUsableSpace() / 1024; System.out.format("%-20s %12d %12d %12d%n", store, total, used, avail); } } }
@Test @Category( FileStores.class ) public void testFileStoreTotalSpaceIsNonNegative() throws IOException { for( FileStore store : FS.getFileStores() ) { assertThat( store.getTotalSpace()).isGreaterThanOrEqualTo( 0L ); } }
@Test @Category( FileStores.class ) public void testFileStoresHaveAName() { for( FileStore store : FS.getFileStores() ) { assertThat( store.name()).isNotNull(); } }
@Test @Category( FileStores.class ) public void testFileStoresHaveAType() { for( FileStore store : FS.getFileStores() ) { assertThat( store.type()).isNotNull(); } }
@Test @Category( FileStores.class ) public void testFileStoreUsableSpaceIsSmallerThanTotal() throws IOException { for( FileStore store : FS.getFileStores() ) { assertThat( store.getTotalSpace()).isGreaterThanOrEqualTo( store.getUsableSpace() ); } }
@Test @Category( FileStores.class ) public void testFileStoreUnallocatedSpaceIsSmallerUsableSpace() throws IOException { for( FileStore store : FS.getFileStores() ) { assertThat( store.getUnallocatedSpace()).isGreaterThanOrEqualTo( store.getUsableSpace() ); } }
@Before public void createStore() throws IOException { // Setup final String name = "test.jar"; final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, name); final FileSystem fs = ShrinkWrapFileSystems.newFileSystem(archive); final FileStore fileStore = fs.getFileStores().iterator().next(); // Set this.fileStore = fileStore; this.archive = archive; this.fileSystem = fs; }
@Test public void getFileStore() throws IOException { Assert.assertTrue("Returned file store was not as expected", fs.getFileStores().iterator().next() == Files.getFileStore(fs.getPath("path"))); }
@Test public void getFileStores() { final Iterable<FileStore> fileStores = fileSystem.getFileStores(); int count = 0; for (final FileStore fileStore : fileStores) { count++; Assert.assertTrue("file store is not of correct type", fileStore instanceof ShrinkWrapFileStore); } Assert.assertEquals("Should only be one file store per file system", 1, count); }