public long getAvailableSizeBytes() throws IOException { return mFileStore.getUsableSpace(); }
private long getUsableSpace() { long usableSpace = 0; try { usableSpace = fileStore.getUsableSpace(); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return usableSpace; }
NumberFormat nf = NumberFormat.getNumberInstance(); for (Path root : FileSystems.getDefault().getRootDirectories()) { System.out.print(root + ": "); try { FileStore store = Files.getFileStore(root); System.out.println("available=" + nf.format(store.getUsableSpace()) + ", total=" + nf.format(store.getTotalSpace())); } catch (IOException e) { System.out.println("error querying space: " + e.toString()); } }
@Override public long getUsableStorageSpace() throws IOException { long usableSpace = 0L; for (final File file : flowFileRepositoryPaths) { usableSpace += Files.getFileStore(file.toPath()).getUsableSpace(); } return usableSpace; }
private boolean hasEnoughDiskSpace(Path path) { try { FileStore fileStore = getFileStore(path); return fileStore.getUsableSpace() > fileStore.getTotalSpace() * (1.0 - maxUsedSpaceThreshold); } catch (IOException e) { throw new PrestoException(OUT_OF_SPILL_SPACE, "Cannot determine free space for spill", e); } } }
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 HealthCheckResponse call() { long diskFreeInBytes; long totalInBytes; try { diskFreeInBytes = fileStore.getUsableSpace(); totalInBytes = fileStore.getTotalSpace(); } catch (IOException e) { throw new HealthCheckException("Failed to obtain disk space data", e); } long usedInBytes = totalInBytes - diskFreeInBytes; long threshold = (long) ((thresholdPercent / 100) * totalInBytes); //Formatter ensures that returned delimiter will be always the same Formatter formatter = new Formatter(Locale.US); return HealthCheckResponse.named("diskSpace") .state(threshold >= usedInBytes) .withData("percentFree", formatter.format("%.2f%%", 100 * ((double) diskFreeInBytes / totalInBytes)).toString()) .withData("free", DiskSpaceHealthCheck.format(diskFreeInBytes)) .withData("freeBytes", diskFreeInBytes) .withData("total", DiskSpaceHealthCheck.format(totalInBytes)) .withData("totalBytes", totalInBytes) .build(); }
@Override public long getUsableSpace() throws IOException { long result = in.getUsableSpace(); if (result < 0) { // see https://bugs.openjdk.java.net/browse/JDK-8162520: result = Long.MAX_VALUE; } return result; }
static NodeEnvironment.NodePath getPathWithMostFreeSpace(NodeEnvironment env) throws IOException { final NodeEnvironment.NodePath[] paths = env.nodePaths(); NodeEnvironment.NodePath bestPath = null; long maxUsableBytes = Long.MIN_VALUE; for (NodeEnvironment.NodePath nodePath : paths) { FileStore fileStore = nodePath.fileStore; long usableBytes = fileStore.getUsableSpace(); assert usableBytes >= 0 : "usable bytes must be >= 0, got: " + usableBytes; if (bestPath == null || usableBytes > maxUsableBytes) { // This path has been determined to be "better" based on the usable bytes maxUsableBytes = usableBytes; bestPath = nodePath; } } return bestPath; }
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; }
BigInteger totFreeSpace = BigInteger.ZERO; for (NodeEnvironment.NodePath nodePath : env.nodePaths()) { totFreeSpace = totFreeSpace.add(BigInteger.valueOf(nodePath.fileStore.getUsableSpace())); for (NodeEnvironment.NodePath nodePath : paths) { FileStore fileStore = nodePath.fileStore; BigInteger usableBytes = BigInteger.valueOf(fileStore.getUsableSpace()); pathsToSpace.put(nodePath, usableBytes);
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 getUsableSpace() throws IOException { return handleLargeFileSystem(fileStore.getUsableSpace()); }
@Override public boolean checkLowDiskSpace() throws IOException { final long freeSpace = fileStore.getUsableSpace(); return freeSpace < freeSpaceLimit; }
@Override public long getUsableSpace() throws IOException { return handleLargeFileSystem(fileStore.getUsableSpace()); }
@Override public long getUsableSpace() throws IOException { long result = in.getUsableSpace(); if (result < 0) { // see https://bugs.openjdk.java.net/browse/JDK-8162520: result = Long.MAX_VALUE; } return result; }
public static long getAvailableSpace(File logLocation) { long usableSpace = -1; try { final FileStore fileStore = Files.getFileStore(logLocation.toPath()); usableSpace = fileStore.getUsableSpace(); } catch (IOException e) { LangUtil.rethrowUnchecked(e); } return usableSpace; }
@Test @Category( { FileStores.class, SizeLimit.class, Exclusive.class } ) public void testFileStoreLimitPreventsCopy() throws IOException { FileStore store = sizeLimitedRoot().getFileSystem().provider().getFileStore( sizeLimitedRoot() ); while( store.getUsableSpace() > FSDescription.BIG_CONTENT_SIZE ) { Files.write( sizeLimitedRoot().resolve( UUID.randomUUID().toString() ), CONTENT_BIG_TXT ); } Path target = sizeLimitedRoot().resolve( "target" ); assertThatThrownBy( () -> Files.copy( fileInLimitedPlayground(), target ) ). isInstanceOf( IOException.class ); }
private boolean hasEnoughDiskSpace(Path path) { try { FileStore fileStore = getFileStore(path); return fileStore.getUsableSpace() > fileStore.getTotalSpace() * (1.0 - maxUsedSpaceThreshold); } catch (IOException e) { throw new PrestoException(OUT_OF_SPILL_SPACE, "Cannot determine free space for spill", e); } } }
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); } }