java.io.File#getTotalSpace ( )源码实例Demo

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

源代码1 项目: DDMQ   文件: UtilAll.java
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);

        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();

        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;

            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }

    return -1;
}
 
源代码2 项目: rocketmq-all-4.1.0-incubating   文件: UtilAll.java
/**
 * 获取磁盘分区空间使用率
 */
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);

        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();

        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;

            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }

    return -1;
}
 
源代码3 项目: feeyo-redisproxy   文件: Util.java
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
    	
        File file = new File(path);
        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();
        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;
            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }
    return -1;
}
 
源代码4 项目: dremio-oss   文件: SpillServiceImpl.java
private boolean isHealthy(Path spillDirPath) {
  if (healthCheckEnabled) {
    final File disk = new File(Path.getPathWithoutSchemeAndAuthority(spillDirPath).toString());
    final double totalSpace = (double) disk.getTotalSpace();
    minDiskSpace = options.minDiskSpace();
    minDiskSpacePercentage = options.minDiskSpacePercentage();
    logger.debug("Check isHealthy for {} minDiskSpace: {} minDiskSpacePercentage: {}",
      spillDirPath.getName(), minDiskSpace, minDiskSpacePercentage);
    final long threshold = Math.max((long) ((totalSpace / 100.0) * minDiskSpacePercentage), minDiskSpace);
    final long available = disk.getFreeSpace();
    if (available < threshold) {
      return false;
    }
  }
  return true;
}
 
源代码5 项目: rocketmq   文件: UtilAll.java
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);

        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();

        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;

            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }

    return -1;
}
 
源代码6 项目: openjdk-jdk9   文件: GetXSpace.java
private static void compareZeroExist() {
    try {
        File f = File.createTempFile("tmp", null, new File("."));

        long [] s = { f.getTotalSpace(), f.getFreeSpace(), f.getUsableSpace() };

        for (int i = 0; i < s.length; i++) {
            if (s[i] == 0L)
                fail(f.getName(), s[i], "==", 0L);
            else
                pass();
        }
    } catch (IOException x) {
        fail("Couldn't create temp file for test");
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: GetXSpace.java
private static void compareZeroExist() {
    try {
        File f = File.createTempFile("tmp", null, new File("."));

        long [] s = { f.getTotalSpace(), f.getFreeSpace(), f.getUsableSpace() };

        for (int i = 0; i < s.length; i++) {
            if (s[i] == 0L)
                fail(f.getName(), s[i], "==", 0L);
            else
                pass();
        }
    } catch (IOException x) {
        fail("Couldn't create temp file for test");
    }
}
 
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);

        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();

        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;

            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }
    return -1;
}
 
源代码9 项目: big-c   文件: RawLocalFileSystem.java
@Override
public FsStatus getStatus(Path p) throws IOException {
  File partition = pathToFile(p == null ? new Path("/") : p);
  //File provides getUsableSpace() and getFreeSpace()
  //File provides no API to obtain used space, assume used = total - free
  return new FsStatus(partition.getTotalSpace(), 
    partition.getTotalSpace() - partition.getFreeSpace(),
    partition.getFreeSpace());
}
 
源代码10 项目: arcusandroid   文件: ClipDownloadControllerImpl.java
protected boolean hasAvailableStorage(long expectedSize) {
    File content = getContentFile();
    double totalSpace = (double) content.getTotalSpace();
    double freeSpace  = (double) content.getFreeSpace();
    double percentFull = 100 - ((freeSpace * 100) / totalSpace);
    double afterSavedSize = (totalSpace - freeSpace) + expectedSize;
    logger.debug("Reporting -> %[{}] Full (download size of [{}] bytes to be added)", percentFull, expectedSize);

    // See: https://developer.android.com/training/basics/data-storage/files.html#GetFreeSpace
    // If the number returned is a few MB more than the size of the data you want to save, or if the file system is
    // less than 90% full, then it's probably safe to proceed. Otherwise, you probably shouldn't write to storage.
    return afterSavedSize < totalSpace && percentFull <= 90D;
}
 
源代码11 项目: jdk8u-jdk   文件: GetXSpace.java
private static void compare(Space s) {
    File f = new File(s.name());
    long ts = f.getTotalSpace();
    long fs = f.getFreeSpace();
    long us = f.getUsableSpace();

    out.format("%s:%n", s.name());
    String fmt = "  %-4s total= %12d free = %12d usable = %12d%n";
    out.format(fmt, "df", s.total(), 0, s.free());
    out.format(fmt, "getX", ts, fs, us);

    // if the file system can dynamically change size, this check will fail
    if (ts != s.total())
        fail(s.name(), s.total(), "!=", ts);
    else
        pass();

    // unix df returns statvfs.f_bavail
    long tsp = (!name.startsWith("Windows") ? us : fs);
    if (!s.woomFree(tsp))
        fail(s.name(), s.free(), "??", tsp);
    else
        pass();

    if (fs > s.total())
        fail(s.name(), s.total(), ">", fs);
    else
        pass();

    if (us > s.total())
        fail(s.name(), s.total(), ">", us);
    else
        pass();
}
 
源代码12 项目: big-c   文件: DUHelper.java
public String check(String folder) {
  if (folder == null)
    throw new IllegalArgumentException("folder");
  File f = new File(folder);

  folderSize = getFileSize(f);
  usage = 1.0*(f.getTotalSpace() - f.getFreeSpace())/ f.getTotalSpace();
  return String.format("used %d files %d disk in use %f", folderSize, fileCount, usage);
}
 
源代码13 项目: Dragonfly   文件: DiskSpaceGcTimer.java
@PostConstruct
public void init() {
    long totalSpace = 0;
    try {
        File file = new File(Constants.DOWNLOAD_HOME);
        totalSpace = file.getTotalSpace();
    } catch (Exception e) {
    }
    long youngGcThreshold = totalSpace > 0 && totalSpace / 4 < 100 * 1024 * 1024 * 1024L ? totalSpace / 4
        : 100 * 1024 * 1024 * 1024L;
    downSpaceCleaner.fillConf(DownSpaceCleaner.SPACE_TYPE_DISK, Constants.DOWNLOAD_HOME,
        5 * 1024 * 1024 * 1024L,
        youngGcThreshold, 1, 2 * 3600 * 1000L);
}
 
源代码14 项目: TencentKona-8   文件: GetXSpace.java
private static void compare(Space s) {
    File f = new File(s.name());
    long ts = f.getTotalSpace();
    long fs = f.getFreeSpace();
    long us = f.getUsableSpace();

    out.format("%s:%n", s.name());
    String fmt = "  %-4s total= %12d free = %12d usable = %12d%n";
    out.format(fmt, "df", s.total(), 0, s.free());
    out.format(fmt, "getX", ts, fs, us);

    // if the file system can dynamically change size, this check will fail
    if (ts != s.total())
        fail(s.name(), s.total(), "!=", ts);
    else
        pass();

    // unix df returns statvfs.f_bavail
    long tsp = (!name.startsWith("Windows") ? us : fs);
    if (!s.woomFree(tsp))
        fail(s.name(), s.free(), "??", tsp);
    else
        pass();

    if (fs > s.total())
        fail(s.name(), s.total(), ">", fs);
    else
        pass();

    if (us > s.total())
        fail(s.name(), s.total(), ">", us);
    else
        pass();
}
 
源代码15 项目: hadoop   文件: DUHelper.java
public String check(String folder) {
  if (folder == null)
    throw new IllegalArgumentException("folder");
  File f = new File(folder);

  folderSize = getFileSize(f);
  usage = 1.0*(f.getTotalSpace() - f.getFreeSpace())/ f.getTotalSpace();
  return String.format("used %d files %d disk in use %f", folderSize, fileCount, usage);
}
 
源代码16 项目: Jpom   文件: AbstractSystemCommander.java
/**
 * 磁盘占用
 *
 * @return 磁盘占用
 */
protected static String getHardDisk() {
    File[] files = File.listRoots();
    double totalSpace = 0;
    double useAbleSpace = 0;
    for (File file : files) {
        double total = file.getTotalSpace();
        totalSpace += total;
        useAbleSpace += total - file.getUsableSpace();
    }
    return String.format("%.2f", useAbleSpace / totalSpace * 100);
}
 
源代码17 项目: jdk8u60   文件: GetXSpace.java
private static void compare(Space s) {
    File f = new File(s.name());
    long ts = f.getTotalSpace();
    long fs = f.getFreeSpace();
    long us = f.getUsableSpace();

    out.format("%s:%n", s.name());
    String fmt = "  %-4s total= %12d free = %12d usable = %12d%n";
    out.format(fmt, "df", s.total(), 0, s.free());
    out.format(fmt, "getX", ts, fs, us);

    // if the file system can dynamically change size, this check will fail
    if (ts != s.total())
        fail(s.name(), s.total(), "!=", ts);
    else
        pass();

    // unix df returns statvfs.f_bavail
    long tsp = (!name.startsWith("Windows") ? us : fs);
    if (!s.woomFree(tsp))
        fail(s.name(), s.free(), "??", tsp);
    else
        pass();

    if (fs > s.total())
        fail(s.name(), s.total(), ">", fs);
    else
        pass();

    if (us > s.total())
        fail(s.name(), s.total(), ">", us);
    else
        pass();
}
 
源代码18 项目: cloudstack   文件: Ovm3StoragePool.java
/**
 * Copy the systemvm.iso in if it doesn't exist or the size differs.
 *
 * @param storageUrl
 * @param poolUuid
 * @param host
 */
private void prepareSecondaryStorageStore(String storageUrl,
        String poolUuid, String host) {
    String mountPoint = storageUrl;

    GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
    try {
        /* double check */
        if (config.getAgentHasMaster() && config.getAgentInOvm3Pool()) {
            LOGGER.debug("Skip systemvm iso copy, leave it to the master");
            return;
        }
        if (lock.lock(3600)) {
            try {
                /*
                 * save src iso real name for reuse, so we don't depend on
                 * other happy little accidents.
                 */
                File srcIso = getSystemVMPatchIsoFile();
                String destPath = mountPoint + "/ISOs/";
                try {
                    StoragePlugin sp = new StoragePlugin(c);
                    FileProperties fp = sp.storagePluginGetFileInfo(
                            poolUuid, host, destPath + "/"
                                    + srcIso.getName());
                    if (fp.getSize() != srcIso.getTotalSpace()) {
                        LOGGER.info(" System VM patch ISO file already exists: "
                                + srcIso.getAbsolutePath().toString()
                                + ", destination: " + destPath);
                    }
                } catch (Exception e) {
                    LOGGER.info("Copy System VM patch ISO file to secondary storage. source ISO: "
                            + srcIso.getAbsolutePath()
                            + ", destination: "
                            + destPath);
                    try {
                        /* Perhaps use a key instead ? */
                        SshHelper
                                .scpTo(c.getIp(), 22, config
                                        .getAgentSshUserName(), null,
                                        config.getAgentSshPassword(),
                                        destPath, srcIso.getAbsolutePath()
                                                .toString(), "0644");
                    } catch (Exception es) {
                        LOGGER.error("Unexpected exception ", es);
                        String msg = "Unable to copy systemvm ISO on secondary storage. src location: "
                                + srcIso.toString()
                                + ", dest location: "
                                + destPath;
                        LOGGER.error(msg);
                        throw new CloudRuntimeException(msg, es);
                    }
                }
            } finally {
                lock.unlock();
            }
        }
    } finally {
        lock.releaseRef();
    }
}
 
源代码19 项目: chipster   文件: Files.java
public static boolean partitionHasUsableSpacePercentage(File file, int percentage) {
	return ((double)file.getUsableSpace()/(double)file.getTotalSpace())*100 >= percentage;
}
 
源代码20 项目: cosmic   文件: JavaStorageLayer.java
@Override
public long getUsedSpace(final String path) {
    final File file = new File(path);
    return file.getTotalSpace() - file.getFreeSpace();
}