本文整理了Java中java.io.File.getUsableSpace()
方法的一些代码示例,展示了File.getUsableSpace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。File.getUsableSpace()
方法的具体详情如下:
包路径:java.io.File
类名称:File
方法名:getUsableSpace
[英]Returns the number of usable free bytes on the partition containing this path. Returns 0 if this path does not exist.
Note that this is likely to be an optimistic over-estimate and should not be taken as a guarantee your application can actually write this many bytes. On Android (and other Unix-based systems), this method returns the number of free bytes available to non-root users, regardless of whether you're actually running as root, and regardless of any quota or other restrictions that might apply to the user. (The getFreeSpace method returns the number of bytes potentially available to root.)
[中]返回包含此路径的分区上可用的空闲字节数。如果此路径不存在,则返回0。
请注意,这可能是一个乐观的过高估计,不应被视为您的应用程序可以实际写入这么多字节的保证。在Android(和其他基于Unix的系统)上,此方法返回非root用户可用的可用字节数,而不管您是否实际以root用户身份运行,也不管可能应用于该用户的任何配额或其他限制。(getFreeSpace方法返回根目录可能可用的字节数。)
代码示例来源:origin: jenkinsci/jenkins
@Override
public Long invoke(File f, VirtualChannel channel) throws IOException {
return f.getUsableSpace();
}
}
代码示例来源:origin: gocd/gocd
public long getUsableSpace(File targetFolder) {
long usableSpace = targetFolder.getUsableSpace();
if (usableSpace < 0) {
// See https://bugs.openjdk.java.net/browse/JDK-8162520
usableSpace = Long.MAX_VALUE;
}
return usableSpace;
}
}
代码示例来源:origin: atomix/atomix
/**
* Returns the amount of usable space remaining.
*
* @return the amount of usable space remaining
*/
public long getUsableSpace() {
return file.getUsableSpace();
}
代码示例来源:origin: h2oai/h2o-2
@Override public long getUsableSpace() {
return _root.getUsableSpace();
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/** @return the usable space remaining on the filesystem in bytes. */
public long getAvailable() {
return dirFile.getUsableSpace();
}
代码示例来源:origin: apache/nifi
/**
* Returns the free capacity for a given path
* @param path path
* @return usable space
*/
public static long getContainerUsableSpace(final Path path) {
return path.toFile().getUsableSpace();
}
代码示例来源:origin: jenkinsci/jenkins
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException {
// if the disk is really filled up we can't even create a single file,
// so calling File.createTempFile and figuring out the directory won't reliably work.
f = new File(System.getProperty("java.io.tmpdir"));
long s = f.getUsableSpace();
if(s<=0) return null;
return new DiskSpace(f.getCanonicalPath(), s);
}
private static final long serialVersionUID = 1L;
代码示例来源:origin: jenkinsci/jenkins
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException {
long s = f.getUsableSpace();
if(s<=0) return null;
return new DiskSpace(f.getCanonicalPath(), s);
}
private static final long serialVersionUID = 1L;
代码示例来源:origin: gocd/gocd
public static long usableSpace(String currentWorkingDir) {
File file = new File(currentWorkingDir, "pipelines");
if (!file.exists()) {
LOGGER.warn("the [{}] should be created when agent starts up, but it seems missing at the moment. Cruise should be able to automatically create it later", file.getAbsolutePath());
}
return file.getUsableSpace();
}
代码示例来源:origin: apache/flume
CachedFSUsableSpace(File fs, long interval) {
this.fs = fs;
this.interval = interval;
this.value = new AtomicLong(fs.getUsableSpace());
this.lastRefresh = new AtomicLong(System.currentTimeMillis());
}
代码示例来源:origin: apache/flume
long getUsableSpace() {
long now = System.currentTimeMillis();
if (now - interval > lastRefresh.get()) {
value.set(fs.getUsableSpace());
lastRefresh.set(now);
}
return Math.max(value.get(), 0L);
}
}
代码示例来源:origin: apache/geode
/**
* Wrapper to enable stubbing of static method call for unit testing
*/
long getLocalDiskAvailable() {
return FileUtils.getUserDirectory().getUsableSpace();
}
代码示例来源:origin: stackoverflow.com
System.out.println("Total space (bytes): " + root.getTotalSpace());
System.out.println("Free space (bytes): " + root.getFreeSpace());
System.out.println("Usable space (bytes): " + root.getUsableSpace());
代码示例来源:origin: gocd/gocd
public String availableDiskSpace() {
File artifactsDir = artifactsDirHolder.getArtifactsDir();
return FileUtils.byteCountToDisplaySize(artifactsDir.getUsableSpace());
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public FsStats fsStats() {
final Map<String, FsStats.Filesystem> filesystems = new HashMap<>(locations.size());
for (File location : locations) {
final String path = location.getAbsolutePath();
final long total = location.getTotalSpace();
final long free = location.getFreeSpace();
final long available = location.getUsableSpace();
final long used = total - free;
final short usedPercent = (short) ((double) used / total * 100);
final FsStats.Filesystem filesystem = FsStats.Filesystem.create(
path, total, free, available, used, usedPercent);
filesystems.put(path, filesystem);
}
return FsStats.create(filesystems);
}
}
代码示例来源:origin: jenkinsci/jenkins
protected void doRun() {
long free = Jenkins.getInstance().getRootDir().getUsableSpace();
long total = Jenkins.getInstance().getRootDir().getTotalSpace();
if(free<=0 || total<=0) {
// information unavailable. pointless to try.
LOGGER.info("JENKINS_HOME disk usage information isn't available. aborting to monitor");
cancel();
return;
}
LOGGER.fine("Monitoring disk usage of JENKINS_HOME. total="+total+" free="+free);
// if it's more than 90% full and less than the minimum, activate
// it's AND and not OR so that small Hudson home won't get a warning,
// and similarly, if you have a 1TB disk, you don't get a warning when you still have 100GB to go.
HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free< FREE_SPACE_THRESHOLD);
}
代码示例来源:origin: atomix/atomix
/**
* Asserts that enough disk space is available to allocate a new segment.
*/
private void assertDiskSpace() {
if (directory().getUsableSpace() < maxSegmentSize() * SEGMENT_BUFFER_FACTOR) {
throw new StorageException.OutOfDiskSpace("Not enough space to allocate a new journal segment");
}
}
代码示例来源:origin: apache/geode
@Test
public void updateSendsUsableSpaceToRecordsStats() {
File dir = mock(File.class);
when(dir.exists()).thenReturn(true);
final long expectedFree = 456;
when(dir.getUsableSpace()).thenReturn(expectedFree);
TestableDiskUsage diskUsage = new TestableDiskUsage(dir);
diskUsage.update(0.0f, 1.0f);
assertThat(diskUsage.getFree()).isEqualTo(expectedFree);
}
代码示例来源:origin: apache/geode
@Test
public void criticalMessageStatesUsageExceedsCritical() {
File dir = mock(File.class);
when(dir.exists()).thenReturn(true);
when(dir.getTotalSpace()).thenReturn(1024L * 1024L * 3L);
when(dir.getUsableSpace()).thenReturn(1024L * 1024L * 2L);
TestableDiskUsage diskUsage = new TestableDiskUsage(dir, 1/* one megabyte */);
assertThat(diskUsage.update(0.0f, 33.2f)).isEqualTo(DiskState.CRITICAL);
assertThat(diskUsage.getNext()).isEqualTo(DiskState.CRITICAL);
assertThat(diskUsage.getPct()).isEqualTo("33.3%");
assertThat(diskUsage.getCriticalMessage())
.isEqualTo("the file system is 33.3% full, which reached the critical threshold of 33.2%.");
}
代码示例来源:origin: apache/geode
@Test
public void criticalMessageStatesUsageExceedsCriticalWithManyDigits() {
File dir = mock(File.class);
when(dir.exists()).thenReturn(true);
when(dir.getTotalSpace()).thenReturn(1024L * 1024L * 3L);
when(dir.getUsableSpace()).thenReturn(1024L * 1024L * 2L);
TestableDiskUsage diskUsage = new TestableDiskUsage(dir, 1/* one megabyte */);
assertThat(diskUsage.update(0.0f, 33.25783495783648593746336f)).isEqualTo(DiskState.CRITICAL);
assertThat(diskUsage.getNext()).isEqualTo(DiskState.CRITICAL);
assertThat(diskUsage.getPct()).isEqualTo("33.3%");
assertThat(diskUsage.getCriticalMessage())
.isEqualTo("the file system is 33.3% full, which reached the critical threshold of 33.3%.");
}
内容来源于网络,如有侵权,请联系作者删除!