java.nio.file.FileStore#getUsableSpace ( )源码实例Demo

下面列出了java.nio.file.FileStore#getUsableSpace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: nexus-public   文件: FileBlobStore.java
@Override
public boolean isStorageAvailable() {
  try {
    FileStore fileStore = Files.getFileStore(contentDir);
    long usableSpace = fileStore.getUsableSpace();
    boolean readOnly = fileStore.isReadOnly();
    boolean result = !readOnly && usableSpace > 0;
    if (!result) {
      log.warn("File blob store '{}' is not writable. Read only: {}. Usable space: {}",
          getBlobStoreConfiguration().getName(), readOnly, usableSpace);
    }
    return result;
  }
  catch (IOException e) {
    log.warn("File blob store '{}' is not writable.", getBlobStoreConfiguration().getName(), e);
    return false;
  }
}
 
源代码2 项目: presto   文件: FileSingleStreamSpillerFactory.java
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);
    }
}
 
源代码3 项目: nyzoVerifier   文件: ConsensusTracker.java
private static long getUsableSpace() {

        // Ensure that the directory exists.
        rootDirectory.mkdirs();

        // Get the usable space.
        long freeSpace = 0L;
        Path path = Paths.get(rootDirectory.getAbsolutePath());
        try {
            FileStore store = Files.getFileStore(path);
            freeSpace = store.getUsableSpace();
        } catch (Exception ignored) { }

        return freeSpace;
    }
 
源代码4 项目: swage   文件: DiskUsageSensor.java
@Override
public void sense(final MetricContext metricContext) throws SenseException
{
    try {
        // Determine the file store for the directory the JVM was started in
        FileStore fileStore = Files.getFileStore(Paths.get(System.getProperty("user.dir")));

        long total = fileStore.getTotalSpace();
        long free = fileStore.getUsableSpace();
        double percent_free = 100.0 * ((double)(total-free)/(double)total);
        metricContext.record(DISK_USED, percent_free, Unit.PERCENT);
    } catch (IOException e) {
        throw new SenseException("Problem reading disk space", e);
    }
}
 
源代码5 项目: lucene-solr   文件: IndexFetcher.java
private static Long getUsableSpace(String dir) {
  try {
    File file = new File(dir);
    if (!file.exists()) {
      file = file.getParentFile();
      if (!file.exists()) {//this is not a disk directory . so just pretend that there is enough space
        return Long.MAX_VALUE;
      }
    }
    FileStore fileStore = Files.getFileStore(file.toPath());
    return fileStore.getUsableSpace();
  } catch (IOException e) {
    throw new SolrException(ErrorCode.SERVER_ERROR, "Could not free disk space", e);
  }
}
 
源代码6 项目: LagMonitor   文件: NativeManager.java
public long getFreeSpace() {
    long freeSpace = 0;
    try {
        FileStore fileStore = Files.getFileStore(Paths.get("."));
        freeSpace = fileStore.getUsableSpace();
    } catch (IOException ioEx) {
        logger.log(Level.WARNING, "Cannot calculate free/total disk space", ioEx);
    }

    return freeSpace;
}
 
源代码7 项目: activemq-artemis   文件: FileStoreMonitor.java
public void tick() {
   synchronized (monitorLock) {
      boolean over = false;
      long usableSpace = 0;
      long totalSpace = 0;

      for (FileStore store : stores) {
         try {
            usableSpace = store.getUsableSpace();
            totalSpace = getTotalSpace(store);
            over = calculateUsage(usableSpace, totalSpace) > maxUsage;
            if (over) {
               break;
            }
         } catch (IOException ioe) {
            ioCriticalErrorListener.onIOException(ioe, "IO Error while calculating disk usage", null);
         } catch (Exception e) {
            logger.warn(e.getMessage(), e);
         }
      }

      for (Callback callback : callbackList) {
         callback.tick(usableSpace, totalSpace);

         if (over) {
            callback.over(usableSpace, totalSpace);
         } else {
            callback.under(usableSpace, totalSpace);
         }
      }
   }
}
 
源代码8 项目: LagMonitor   文件: NativeManager.java
public long getFreeSpace() {
    long freeSpace = 0;
    try {
        FileStore fileStore = Files.getFileStore(Paths.get("."));
        freeSpace = fileStore.getUsableSpace();
    } catch (IOException ioEx) {
        logger.log(Level.WARNING, "Cannot calculate free/total disk space", ioEx);
    }

    return freeSpace;
}
 
源代码9 项目: jsr203-hadoop   文件: TestFileSystem.java
/**
 * Simple test to check {@link FileStore} support.
 *
 * @throws IOException
 */
@Test
public void getFileStores() throws IOException {
  Path pathToTest = Paths.get(clusterUri);

  Iterable<FileStore> fileStores = pathToTest.getFileSystem().getFileStores();
  for (FileStore store : fileStores) {
    store.getUsableSpace();
    assertNotNull(store.toString());
  }
}
 
源代码10 项目: simple-nfs   文件: LocalFileSystem.java
@Override
public FsStat getFsStat() throws IOException {
    FileStore store = Files.getFileStore(_root);
    long total = store.getTotalSpace();
    long free = store.getUsableSpace();
    return new FsStat(total, Long.MAX_VALUE, total-free, pathToInode.size());
}
 
源代码11 项目: spliceengine   文件: FileSystemConfiguration.java
public long freeDiskBytes() throws IOException {
    Iterable<FileStore> fileStores = localFileSystem.getFileStores();
    long totalUsableSpace = 0l;
    for(FileStore fs:fileStores){
        totalUsableSpace+=fs.getUsableSpace();
    }
    return totalUsableSpace;
}
 
源代码12 项目: java-1-class-demos   文件: FileStoreBasics.java
public static String freeSpaceFormatted(FileStore store) throws Exception {
	long mb = store.getUsableSpace() / (1000*1000); // 10^6 converts to megabytes.
	return mb + " mb";
}
 
源代码13 项目: levelup-java-examples   文件: GetAvailableSpace.java
@Test
public void get_available_space_nio () throws IOException {

	FileStore store = Files.getFileStore(source);

	long availableSpace = store.getUsableSpace() / 1024;
	
	assertTrue(availableSpace > 0);
}