public FileSystemProps perform() { try { Path target = vertx.resolveFile(path).toPath(); FileStore fs = Files.getFileStore(target); return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace()); } catch (IOException e) { throw new FileSystemException(e); } } };
@Override public long getUnallocatedSpace() throws IOException { long result = in.getUnallocatedSpace(); if (result < 0) { // see https://bugs.openjdk.java.net/browse/JDK-8162520: result = Long.MAX_VALUE; } return result; }
public static FsInfo.Path getFSInfo(NodePath nodePath) throws IOException { FsInfo.Path fsPath = new FsInfo.Path(); fsPath.path = nodePath.path.toAbsolutePath().toString(); // NOTE: we use already cached (on node startup) FileStore and spins // since recomputing these once per second (default) could be costly, // and they should not change: fsPath.total = adjustForHugeFilesystems(nodePath.fileStore.getTotalSpace()); fsPath.free = adjustForHugeFilesystems(nodePath.fileStore.getUnallocatedSpace()); fsPath.available = adjustForHugeFilesystems(nodePath.fileStore.getUsableSpace()); fsPath.type = nodePath.fileStore.type(); fsPath.mount = nodePath.fileStore.toString(); return fsPath; }
public FileSystemProps perform() { try { Path target = vertx.resolveFile(path).toPath(); FileStore fs = Files.getFileStore(target); return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace()); } catch (IOException e) { throw new FileSystemException(e); } } };
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { long diskFreeInBytes = fileStore.getUnallocatedSpace(); if (diskFreeInBytes >= thresholdBytes) { builder.up(); } else { builder.down(); } long totalSpaceInBytes = fileStore.getTotalSpace(); builder.withDetail("disk.free", diskFreeInBytes); builder.withDetail("disk.total", totalSpaceInBytes); } }
@Override public long getUnallocatedSpace() throws IOException { return handleLargeFileSystem(fileStore.getUnallocatedSpace()); }
@Override public long getUnallocatedSpace() throws IOException { return handleLargeFileSystem(fileStore.getUnallocatedSpace()); }
@Override public long getUnallocatedSpace() throws IOException { long result = in.getUnallocatedSpace(); if (result < 0) { // see https://bugs.openjdk.java.net/browse/JDK-8162520: result = Long.MAX_VALUE; } return result; }
@Override public long getUnallocatedSpace() throws IOException { return handleLargeFileSystem(fileStore.getUnallocatedSpace()); }
@Override public long getUnallocatedSpace() throws IOException { long result = in.getUnallocatedSpace(); if (result < 0) { // see https://bugs.openjdk.java.net/browse/JDK-8162520: result = Long.MAX_VALUE; } return result; }
public SpaceAvailableExtensionInfo(FileStore store) throws IOException { bytesOnDevice = store.getTotalSpace(); long unallocated = store.getUnallocatedSpace(); long usable = store.getUsableSpace(); unusedBytesOnDevice = Math.max(unallocated, usable); // the rest are intentionally left zero indicating "UNKNOWN" }
public SpaceAvailableExtensionInfo(FileStore store) throws IOException { bytesOnDevice = store.getTotalSpace(); long unallocated = store.getUnallocatedSpace(); long usable = store.getUsableSpace(); unusedBytesOnDevice = Math.max(unallocated, usable); // the rest are intentionally left zero indicating "UNKNOWN" }
@Override public long getUnallocatedSpace() { try { return getFileStore().getUnallocatedSpace(); } catch (IOException e) { throw new StorageException(e); } }
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 testFileStoreUnallocatedSpaceIsSmallerUsableSpace() throws IOException { for( FileStore store : FS.getFileStores() ) { assertThat( store.getUnallocatedSpace()).isGreaterThanOrEqualTo( store.getUsableSpace() ); } }
@Override public Space get() throws BackgroundException { final Path home = new DefaultHomeFinderService(session).find(); try { final FileStore store = Files.getFileStore(session.toPath(home)); return new Space(store.getTotalSpace() - store.getUnallocatedSpace(), store.getUnallocatedSpace()); } catch(IOException e) { throw new LocalExceptionMappingService().map("Failure to read attributes of {0}", e, home); } } }
public FileSystemProps action() throws Exception { FileStore fs = Files.getFileStore(target); return new FileSystemProps(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace()); } };
@Test @Category( { FileStores.class, Exclusive.class, Writable.class } ) public void testPathFileStoreGrowingFileLowersUsableSpace() throws IOException { Path file = fileTA(); FileStore store = FS.provider().getFileStore( file ); long before = store.getUnallocatedSpace(); for ( int i = 0; i < 10; i++ ) { Files.write( file, CONTENT_BIG_TXT, StandardOpenOption.APPEND ); } assertThat( store.getUsableSpace()).isLessThanOrEqualTo( before ); }
DiskStatus(FileStore fileStore) throws IOException { this(fileStore.type(), BytesValues.of(fileStore.getUsableSpace()), BytesValues.of(fileStore.getTotalSpace()), BytesValues.of(fileStore.getTotalSpace() - fileStore.getUnallocatedSpace()), (float) (fileStore.getTotalSpace() - fileStore.getUnallocatedSpace()) / fileStore.getTotalSpace() * 100); } }
@Test public void unallocatedSpace() throws IOException { // We can't really test this value properly as the JVM can reallocate memory inbetween calls, so just ensure // we're returning something sane Assert.assertTrue("Unallocated space is not returning a positive integer", this.fileStore.getUnallocatedSpace() > 0); }