Java Code Examples for org.apache.commons.io.FileUtils#sizeOfDirectory()

The following examples show how to use org.apache.commons.io.FileUtils#sizeOfDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSize.java    From incubator-iotdb with Apache License 2.0 6 votes vote down vote up
private long collectSeqFileSize(EnumMap<FileSizeConstants, Long> fileSizes,
    FileSizeConstants kinds) {
  long fileSize = INIT_VALUE_IF_FILE_NOT_EXIST;
  for (String sequenceDir : config.getDataDirs()) {
    if (sequenceDir.contains("unsequence")) {
      continue;
    }
    File settledFile = SystemFileFactory.INSTANCE.getFile(sequenceDir);
    if (settledFile.exists()) {
      try {
        fileSize += FileUtils.sizeOfDirectory(settledFile);
      } catch (Exception e) {
        logger.error("Meet error while trying to get {} size with dir {} .", kinds,
            sequenceDir, e);
        fileSizes.put(kinds, ABNORMAL_VALUE);
      }
    }
  }
  return fileSize;
}
 
Example 2
Source File: SizeFileComparator.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Compare the length of two files.
 * 
 * @param file1 The first file to compare
 * @param file2 The second file to compare
 * @return a negative value if the first file's length
 * is less than the second, zero if the lengths are the
 * same and a positive value if the first files length
 * is greater than the second file.
 * 
 */
public int compare(File file1, File file2) {
    long size1 = 0;
    if (file1.isDirectory()) {
        size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0;
    } else {
        size1 = file1.length();
    }
    long size2 = 0;
    if (file2.isDirectory()) {
        size2 = sumDirectoryContents && file2.exists() ? FileUtils.sizeOfDirectory(file2) : 0;
    } else {
        size2 = file2.length();
    }
    long result = size1 - size2;
    if (result < 0) {
        return -1;
    } else if (result > 0) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 3
Source File: SizeFileComparator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compare the length of two files.
 * 
 * @param file1 The first file to compare
 * @param file2 The second file to compare
 * @return a negative value if the first file's length
 * is less than the second, zero if the lengths are the
 * same and a positive value if the first files length
 * is greater than the second file.
 * 
 */
public int compare(final File file1, final File file2) {
    long size1 = 0;
    if (file1.isDirectory()) {
        size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0;
    } else {
        size1 = file1.length();
    }
    long size2 = 0;
    if (file2.isDirectory()) {
        size2 = sumDirectoryContents && file2.exists() ? FileUtils.sizeOfDirectory(file2) : 0;
    } else {
        size2 = file2.length();
    }
    final long result = size1 - size2;
    if (result < 0) {
        return -1;
    } else if (result > 0) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 4
Source File: Monitor.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
@Override
public long getDataSizeInByte() {
  try {
    long totalSize = 0;
    for (String dataDir : config.getDataDirs()) {
      totalSize += FileUtils.sizeOfDirectory(SystemFileFactory.INSTANCE.getFile(dataDir));
    }
    return totalSize;
  } catch (Exception e) {
    logger.error("meet error while trying to get data size.", e);
    return -1;
  }
}
 
Example 5
Source File: FSStorer.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public long getTotalSize() {
	long size = 0;
	File docDir = getRoot();
	if (docDir.exists())
		size = FileUtils.sizeOfDirectory(docDir);

	return size;
}
 
Example 6
Source File: ExprFileDirSizeBytes.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected Number[] get(Event e) {
  Path pth = Paths.get(skUtilities.getDefaultPath(path.getSingle(e)));
  try {
    if (ty == 0) {
      return new Number[]{Files.size(pth)};
    } else {
      return new Number[]{FileUtils.sizeOfDirectory(pth.toFile())};
    }
  } catch (Exception x) {
    skUtilities.prSysE("File: '" + pth + "' doesn't exist!", getClass().getSimpleName());
  }
  return null;
}
 
Example 7
Source File: JavaFolderSizeUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenGetFolderSizeUsingApacheCommonsIO_thenCorrect() {
    final File folder = new File(path);
    final long size = FileUtils.sizeOfDirectory(folder);

    assertEquals(EXPECTED_SIZE, size);
}
 
Example 8
Source File: BookKeeperClientRFLibrary.java    From rubix with Apache License 2.0 5 votes vote down vote up
/**
 * Get the combined size of all configured cache directories.
 *
 * @param dirPath     The root path for the cache directories
 * @param dirSuffix   The cache directory suffix.
 * @param numDisks    The expected number of cache disks.
 * @return The size of the cache in MB.
 */
public long getCacheDirSizeMb(String dirPath, String dirSuffix, int numDisks)
{
  long cacheSize = 0;
  for (int disk = 0; disk < numDisks; disk++) {
    long cacheDirSize = FileUtils.sizeOfDirectory(new File(dirPath + disk + dirSuffix));
    cacheSize += cacheDirSize;
  }

  return BYTES.toMB(cacheSize);
}
 
Example 9
Source File: SegmentLocalFSDirectory.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public long getDiskSizeBytes() {
  // [PINOT-3479] For newly added refresh segments, the new segment will
  // replace the old segment on disk before the new segment is loaded.
  // That means, the new segment may be in the pre-processing state.
  // So, the segment format may not have been converted, and inverted indexes
  // or default columns will not exist.

  // check that v3 subdirectory exists since the format may not have been converted
  if (segmentDirectory.exists()) {
    try {
      return FileUtils.sizeOfDirectory(segmentDirectory.toPath().toFile());
    } catch (IllegalArgumentException e) {
      LOGGER.error("Failed to read disk size for directory: ", segmentDirectory.getAbsolutePath());
      return -1;
    }
  } else {
    if (!SegmentDirectoryPaths.isV3Directory(segmentDirectory)) {
      LOGGER
          .error("Segment directory: {} not found on disk and is not v3 format", segmentDirectory.getAbsolutePath());
      return -1;
    }
    File[] files = segmentDirectory.getParentFile().listFiles();
    if (files == null) {
      LOGGER.warn("Empty list of files for path: {}, segmentDirectory: {}", segmentDirectory.getParentFile(),
          segmentDirectory);
      return -1;
    }

    long size = 0L;
    for (File file : files) {
      if (file.isFile()) {
        size += file.length();
      }
    }
    return size;
  }
}
 
Example 10
Source File: NfsSecondaryStorageResource.java    From cosmic with Apache License 2.0 5 votes vote down vote up
private synchronized void checkSecondaryStorageResourceLimit(final TemplateOrVolumePostUploadCommand cmd, final int contentLengthInGB) {
    final String rootDir = getRootDir(cmd.getDataTo()) + File.separator;
    final long accountId = cmd.getAccountId();

    final long accountTemplateDirSize = 0;
    final File accountTemplateDir = new File(rootDir + getTemplatePathForAccount(accountId));
    if (accountTemplateDir.exists()) {
        FileUtils.sizeOfDirectory(accountTemplateDir);
    }
    long accountVolumeDirSize = 0;
    final File accountVolumeDir = new File(rootDir + getVolumePathForAccount(accountId));
    if (accountVolumeDir.exists()) {
        accountVolumeDirSize = FileUtils.sizeOfDirectory(accountVolumeDir);
    }
    long accountSnapshotDirSize = 0;
    final File accountSnapshotDir = new File(rootDir + getSnapshotPathForAccount(accountId));
    if (accountSnapshotDir.exists()) {
        accountSnapshotDirSize = FileUtils.sizeOfDirectory(accountSnapshotDir);
    }
    s_logger.debug("accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " +
            accountVolumeDirSize);

    final int accountDirSizeInGB = getSizeInGB(accountTemplateDirSize + accountSnapshotDirSize + accountVolumeDirSize);
    final int defaultMaxAccountSecondaryStorageInGB = Integer.parseInt(cmd.getDefaultMaxAccountSecondaryStorage());

    if (accountDirSizeInGB + contentLengthInGB > defaultMaxAccountSecondaryStorageInGB) {
        s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxAccountSecondaryStorageInGB: " + defaultMaxAccountSecondaryStorageInGB + " contentLengthInGB:"
                + contentLengthInGB);
        final String errorMessage = "Maximum number of resources of type secondary_storage for account has exceeded";
        updateStateMapWithError(cmd.getEntityUUID(), errorMessage);
        throw new InvalidParameterValueException(errorMessage);
    }
}
 
Example 11
Source File: GitProjectRepoTest.java    From writelatex-git-bridge with MIT License 4 votes vote down vote up
private static long repoSize(ProjectRepo repo) {
    return FileUtils.sizeOfDirectory(repo.getProjectDir());
}
 
Example 12
Source File: RocksDBLookupTableCache.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public long getTotalCacheSize() {
    return FileUtils.sizeOfDirectory(new File(getCacheBasePath(config)));
}
 
Example 13
Source File: JCSCache.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
@Override
public long size() {
	return FileUtils.sizeOfDirectory(getFile("jcs.auxiliary.DC.attributes.DiskPath"));
}
 
Example 14
Source File: ExtractorUtils.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private static long getTotalSize(String directory) {
  File diskDirFile = new File(directory);
  return FileUtils.sizeOfDirectory(diskDirFile)/1024;
}
 
Example 15
Source File: RocksDBLookupTableCache.java    From kylin with Apache License 2.0 4 votes vote down vote up
public CachedTableInfo(String cachePath) {
    this.cachePath = cachePath;
    this.dbSize = FileUtils.sizeOfDirectory(new File(cachePath));
}
 
Example 16
Source File: RocksDBLookupTableCache.java    From kylin with Apache License 2.0 4 votes vote down vote up
public long getTotalCacheSize() {
    return FileUtils.sizeOfDirectory(new File(getCacheBasePath(config)));
}
 
Example 17
Source File: LocalServerMode.java    From wangmarket with Apache License 2.0 4 votes vote down vote up
@Override
public long getDirectorySize(String path) {
	directoryInit(path);
	return FileUtils.sizeOfDirectory(new File(AttachmentFile.localFilePath+path));
}
 
Example 18
Source File: ExtractorUtils.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private static long getTotalSize(String directory) {
  File diskDirFile = new File(directory);
  return FileUtils.sizeOfDirectory(diskDirFile)/1024;
}
 
Example 19
Source File: HsqlDAO2.java    From MtgDesktopCompanion with GNU General Public License v3.0 3 votes vote down vote up
@Override
public long getDBSize() {
	
	if(getString(MODE).equals("mem"))
		return 0;
	
	if(getFile(SERVERNAME).exists())
		return FileUtils.sizeOfDirectory(getFile(SERVERNAME));
	else
		return 0;
	
	
}
 
Example 20
Source File: FileCache.java    From MtgDesktopCompanion with GNU General Public License v3.0 3 votes vote down vote up
@Override
public long size() {
	
	if(dir!=null)
		return FileUtils.sizeOfDirectory(dir);
	
	
	return 0;
}