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

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

源代码1 项目: Quelea   文件: AddDVDActionHandler.java
/**
 * Get the location of the DVD, or null if no DVD can be found.
 * <p>
 * @return the DVD location.
 */
private String getLocation() {
    FileSystem fs = FileSystems.getDefault();
    for(Path rootPath : fs.getRootDirectories()) {
        try {
            FileStore store = Files.getFileStore(rootPath);
            if(store.type().toLowerCase().contains("udf")) {
                if(store.getTotalSpace()>10000000000L) { //Blu-ray
                    return "bluray:///" + rootPath.toString();
                }
                else {
                    return "dvdsimple:///" + rootPath.toString(); //DVD
                }
            }
        }
        catch(IOException ex) {
            //Never mind
        }
    }
    return null;
}
 
源代码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 项目: swage   文件: DiskUsageSensor.java
@Override
public TypedMap addContext(final TypedMap existing)
{
    try {
        // Determine the file store for the directory the JVM was started in
        FileStore fileStore = Files.getFileStore(Paths.get(System.getProperty("user.dir")));

        long size = fileStore.getTotalSpace();
        long gb_size = size/(K*K*K);
        return ImmutableTypedMap.Builder.from(existing).add(DISK_SIZE, Long.valueOf(gb_size)).build();
    } catch (IOException e) {
        // log?
        return existing;
    }
}
 
源代码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 项目: cyberduck   文件: LocalQuotaFeature.java
@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);
    }
}
 
源代码6 项目: LagMonitor   文件: NativeManager.java
public long getTotalSpace() {
    long totalSpace = 0;
    try {
        FileStore fileStore = Files.getFileStore(Paths.get("."));
        totalSpace = fileStore.getTotalSpace();
    } catch (IOException ioEx) {
        logger.log(Level.WARNING, "Cannot calculate free disk space", ioEx);
    }

    return totalSpace;
}
 
源代码7 项目: packagedrone   文件: ConfigController.java
private Double freeSpace ()
{
    try
    {
        final String base = System.getProperty ( SYSPROP_STORAGE_BASE );
        final Path p = Paths.get ( base );

        final FileStore store = Files.getFileStore ( p );
        return (double)store.getUnallocatedSpace () / (double)store.getTotalSpace ();
    }
    catch ( final Exception e )
    {
        return null;
    }
}
 
源代码8 项目: activemq-artemis   文件: FileStoreMonitor.java
private long getTotalSpace(FileStore store) throws IOException {
   long totalSpace = store.getTotalSpace();
   if (totalSpace < 0) {
      totalSpace = Long.MAX_VALUE;
   }
   return totalSpace;
}
 
源代码9 项目: LagMonitor   文件: NativeManager.java
public long getTotalSpace() {
    long totalSpace = 0;
    try {
        FileStore fileStore = Files.getFileStore(Paths.get("."));
        totalSpace = fileStore.getTotalSpace();
    } catch (IOException ioEx) {
        logger.log(Level.WARNING, "Cannot calculate free disk space", ioEx);
    }

    return totalSpace;
}
 
源代码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 项目: Nukkit   文件: BugReportGenerator.java
private String generate() throws IOException {
    File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
    if (!reports.isDirectory()) {
        reports.mkdirs();
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
    String date = simpleDateFormat.format(new Date());

    StringBuilder model = new StringBuilder();
    long totalDiskSpace = 0;
    int diskNum = 0;
    for (Path root : FileSystems.getDefault().getRootDirectories()) {
        try {
            FileStore store = Files.getFileStore(root);
            model.append("Disk ").append(diskNum++).append(":(avail=").append(getCount(store.getUsableSpace(), true))
                    .append(", total=").append(getCount(store.getTotalSpace(), true))
                    .append(") ");
            totalDiskSpace += store.getTotalSpace();
        } catch (IOException e) {
            //
        }
    }

    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));

    StackTraceElement[] stackTrace = throwable.getStackTrace();
    boolean pluginError = false;
    if (stackTrace.length > 0) {
        pluginError = !throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit");
    }


    File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
    mdReport.createNewFile();
    String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));

    String cpuType = System.getenv("PROCESSOR_IDENTIFIER");
    OperatingSystemMXBean osMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
    content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
    content = content.replace("${HOSTOS}", osMXBean.getName() + "-" + osMXBean.getArch() + " [" + osMXBean.getVersion() + "]");
    content = content.replace("${MEMORY}", getCount(osMXBean.getTotalPhysicalMemorySize(), true));
    content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSpace, true));
    content = content.replace("${CPU_TYPE}", cpuType == null ? "UNKNOWN" : cpuType);
    content = content.replace("${AVAILABLE_CORE}", String.valueOf(osMXBean.getAvailableProcessors()));
    content = content.replace("${STACKTRACE}", stringWriter.toString());
    content = content.replace("${PLUGIN_ERROR}", Boolean.toString(pluginError).toUpperCase());
    content = content.replace("${STORAGE_TYPE}", model.toString());

    Utils.writeFile(mdReport, content);

    return mdReport.getAbsolutePath();
}
 
源代码12 项目: levelup-java-examples   文件: GetTotalSpace.java
@Test
public void get_file_store_total_space () throws IOException {

	FileStore store = Files.getFileStore(source);

	long totalSpace = store.getTotalSpace();
	
	assertTrue(totalSpace > 0);
}
 
源代码13 项目: levelup-java-examples   文件: GetUsedSpace.java
@Test
public void get_used_space_nio () throws IOException {

	FileStore store = Files.getFileStore(source);

	long usedSpace = (store.getTotalSpace() -
             store.getUnallocatedSpace()) / 1024;
	
	assertTrue(usedSpace > 0);
}