org.apache.commons.io.FileUtils.sizeOfDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中org.apache.commons.io.FileUtils.sizeOfDirectory()方法的一些代码示例,展示了FileUtils.sizeOfDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.sizeOfDirectory()方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:sizeOfDirectory

FileUtils.sizeOfDirectory介绍

[英]Counts the size of a directory recursively (sum of the length of all files).
[中]递归计算目录的大小(所有文件的长度之和)。

代码示例

代码示例来源:origin: apache/kylin

public CachedTableInfo(String cachePath) {
  this.cachePath = cachePath;
  this.dbSize = FileUtils.sizeOfDirectory(new File(cachePath));
}

代码示例来源:origin: commons-io/commons-io

long size1 = 0;
if (file1.isDirectory()) {
  size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0;
} else {
  size1 = file1.length();
  size2 = sumDirectoryContents && file2.exists() ? FileUtils.sizeOfDirectory(file2) : 0;
} else {
  size2 = file2.length();

代码示例来源:origin: gocd/gocd

private String getConfigRepoDisplaySize() {
  return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(workingDir));
}

代码示例来源:origin: apache/kylin

public long getTotalCacheSize() {
  return FileUtils.sizeOfDirectory(new File(getCacheBasePath(config)));
}

代码示例来源:origin: apache/incubator-pinot

return FileUtils.sizeOfDirectory(segmentDirectory.toPath().toFile());
} catch (IllegalArgumentException e) {
 LOGGER.error("Failed to read disk size for direcotry: ", segmentDirectory.getAbsolutePath());

代码示例来源:origin: Alluxio/alluxio

private boolean addDirectoryInfo(String path, long quota, Map<String, MountedStorage> storageMap)
  throws IOException {
 File file = new File(path);
 if (!file.exists()) {
  System.err.format("Path %s does not exist.%n", path);
  return false;
 }
 if (!file.isDirectory()) {
  System.err.format("Path %s is not a valid directory.%n", path);
  return false;
 }
 long directorySize = FileUtils.sizeOfDirectory(file);
 // gets mounted FileStore that backs the directory of the given path
 FileStore store = Files.getFileStore(Paths.get(path));
 MountedStorage storage = storageMap.get(store.name());
 if (storage == null) {
  storage = new MountedStorage(store);
  storageMap.put(store.name(), storage);
 }
 storage.addDirectoryInfo(path, quota, directorySize);
 return true;
}

代码示例来源:origin: SonarSource/sonarqube

private File generateReportFile() {
 try {
  long startTime = System.currentTimeMillis();
  for (ReportPublisherStep publisher : publishers) {
   publisher.publish(writer);
  }
  long stopTime = System.currentTimeMillis();
  LOG.info("Analysis report generated in {}ms, dir size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir.toFile())));
  startTime = System.currentTimeMillis();
  File reportZip = temp.newFile("scanner-report", ".zip");
  ZipUtils.zipDir(reportDir.toFile(), reportZip);
  stopTime = System.currentTimeMillis();
  LOG.info("Analysis report compressed in {}ms, zip size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip)));
  return reportZip;
 } catch (IOException e) {
  throw new IllegalStateException("Unable to prepare analysis report", e);
 }
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldUploadArtifactChecksumForADirectory() throws IOException {
  String data = "Some text whose checksum can be asserted";
  String secondData = "some more";
  FileUtils.writeStringToFile(tempFile, data, UTF_8);
  File anotherFile = new File(artifactFolder, "bond/james_bond/another_file");
  FileUtils.writeStringToFile(anotherFile, secondData, UTF_8);
  when(httpService.upload(eq("http://baseurl/artifacts/dest?attempt=1&buildId=build42"), eq(FileUtils.sizeOfDirectory(artifactFolder)), any(File.class), eq(expectedProperties(data, secondData)))).thenReturn(HttpServletResponse.SC_OK);
  artifactsRepository.upload(console, artifactFolder, "dest", "build42");
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldUploadArtifactChecksumForADirectory() throws IOException {
  String data = "Some text whose checksum can be asserted";
  String secondData = "some more";
  FileUtils.writeStringToFile(tempFile, data, UTF_8);
  File anotherFile = new File(artifactFolder, "bond/james_bond/another_file");
  FileUtils.writeStringToFile(anotherFile, secondData, UTF_8);
  when(httpService.upload(any(String.class), eq(FileUtils.sizeOfDirectory(artifactFolder)), any(File.class), eq(expectedProperties(data, secondData)))).thenReturn(HttpServletResponse.SC_OK);
  goArtifactsManipulatorStub.publish(goPublisher, "dest", artifactFolder, jobIdentifier);
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testCopyDirectoryToGrandChild() throws Exception {
  final File grandParentDir = new File(getTestDirectory(), "grandparent");
  final File parentDir = new File(grandParentDir, "parent");
  final File childDir = new File(parentDir, "child");
  createFilesForTestCopyDirectory(grandParentDir, parentDir, childDir);
  final long expectedCount = LIST_WALKER.list(grandParentDir).size() * 2;
  final long expectedSize = FileUtils.sizeOfDirectory(grandParentDir) * 2;
  FileUtils.copyDirectory(grandParentDir, childDir);
  assertEquals(expectedCount, LIST_WALKER.list(grandParentDir).size());
  assertEquals(expectedSize, FileUtils.sizeOfDirectory(grandParentDir));
  assertTrue("Size > 0", expectedSize > 0);
}

代码示例来源:origin: apache/incubator-pinot

public MemoryEstimator(TableConfig tableConfig, File sampleCompletedSegment, long sampleSegmentConsumedSeconds) {
 _tableConfig = tableConfig;
 _sampleCompletedSegment = sampleCompletedSegment;
 _sampleSegmentConsumedSeconds = sampleSegmentConsumedSeconds;
 _sampleCompletedSegmentSizeBytes = FileUtils.sizeOfDirectory(_sampleCompletedSegment);
 try {
  _segmentMetadata = new SegmentMetadataImpl(_sampleCompletedSegment);
 } catch (Exception e) {
  throw new RuntimeException("Caught exception when reading segment index dir", e);
 }
 if (CollectionUtils.isNotEmpty(_tableConfig.getIndexingConfig().getNoDictionaryColumns())) {
  _noDictionaryColumns.addAll(_tableConfig.getIndexingConfig().getNoDictionaryColumns());
 }
 if (CollectionUtils.isNotEmpty(_tableConfig.getIndexingConfig().getInvertedIndexColumns())) {
  _invertedIndexColumns.addAll(_tableConfig.getIndexingConfig().getInvertedIndexColumns());
 }
 _avgMultiValues = getAvgMultiValues();
 _tableDataDir = new File(TMP_DIR, _segmentMetadata.getTableName());
 try {
  FileUtils.deleteDirectory(_tableDataDir);
 } catch (IOException e) {
  throw new RuntimeException("Exception in deleting directory " + _tableDataDir.getAbsolutePath(), e);
 }
 _tableDataDir.mkdir();
}

代码示例来源:origin: gocd/gocd

size = FileUtils.sizeOfDirectory(source);
} else {
  size = source.length();

代码示例来源:origin: commons-io/commons-io

@Test
public void testCopyDirectoryToChild() throws Exception {
  final File grandParentDir = new File(getTestDirectory(), "grandparent");
  final File parentDir = new File(grandParentDir, "parent");
  final File childDir = new File(parentDir, "child");
  createFilesForTestCopyDirectory(grandParentDir, parentDir, childDir);
  final long expectedCount = LIST_WALKER.list(grandParentDir).size() +
      LIST_WALKER.list(parentDir).size();
  final long expectedSize = FileUtils.sizeOfDirectory(grandParentDir) +
      FileUtils.sizeOfDirectory(parentDir);
  FileUtils.copyDirectory(parentDir, childDir);
  assertEquals(expectedCount, LIST_WALKER.list(grandParentDir).size());
  assertEquals(expectedSize, FileUtils.sizeOfDirectory(grandParentDir));
  assertTrue("Count > 0", expectedCount > 0);
  assertTrue("Size > 0", expectedSize > 0);
}

代码示例来源:origin: gocd/gocd

size = FileUtils.sizeOfDirectory(file);
} else {
  size = file.length();

代码示例来源:origin: commons-io/commons-io

final long sizeOfSrcDirectory = FileUtils.sizeOfDirectory(srcDir);
assertTrue("Size > 0", sizeOfSrcDirectory > 0);
assertEquals("Check size", sizeOfSrcDirectory, FileUtils.sizeOfDirectory(destDir));
assertTrue(new File(destDir, "sub/A.txt").exists());
FileUtils.deleteDirectory(destDir);

代码示例来源:origin: commons-io/commons-io

final long srcSize = FileUtils.sizeOfDirectory(srcDir);
assertTrue("Size > 0", srcSize > 0);
assertEquals(srcSize, FileUtils.sizeOfDirectory(destDir));
assertTrue(new File(destDir, "sub/A.txt").exists());

代码示例来源:origin: commons-io/commons-io

@Test
public void testSizeOfDirectory() throws Exception {
  final File file = new File(getTestDirectory(), getName());
  // Non-existent file
  try {
    FileUtils.sizeOfDirectory(file);
    fail("Exception expected.");
  } catch (final IllegalArgumentException ignore) {
  }
  // Creates file
  file.createNewFile();
  // Existing file
  try {
    FileUtils.sizeOfDirectory(file);
    fail("Exception expected.");
  } catch (final IllegalArgumentException ignore) {
  }
  // Existing directory
  file.delete();
  file.mkdir();
  // Create a cyclic symlink
  this.createCircularSymLink(file);
  assertEquals(
      "Unexpected directory size",
      TEST_DIRECTORY_SIZE,
      FileUtils.sizeOfDirectory(file));
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void explode_is_reentrant() throws Exception {
 PluginInfo info = PluginInfo.create(plugin1Jar());
 ExplodedPlugin exploded1 = underTest.explode(info);
 long dirSize1 = sizeOfDirectory(exploded1.getMain().getParentFile());
 ExplodedPlugin exploded2 = underTest.explode(info);
 long dirSize2 = sizeOfDirectory(exploded2.getMain().getParentFile());
 assertThat(exploded2.getMain().getCanonicalPath()).isEqualTo(exploded1.getMain().getCanonicalPath());
 assertThat(dirSize1).isEqualTo(dirSize2);
}

代码示例来源:origin: commons-io/commons-io

final long srcSize = FileUtils.sizeOfDirectory(srcDir);
assertTrue("Size > 0", srcSize > 0);
assertEquals("Check size", srcSize, FileUtils.sizeOfDirectory(actualDestDir));
assertTrue(new File(actualDestDir, "sub/A.txt").exists());
FileUtils.deleteDirectory(destDir);

代码示例来源:origin: SonarSource/sonarqube

@Test
public void sizeOf_sums_sizes_of_all_files_in_directory() throws IOException {
 File dir = temporaryFolder.newFolder();
 File child = new File(dir, "child.txt");
 File grandChild1 = new File(dir, "grand/child1.txt");
 File grandChild2 = new File(dir, "grand/child2.txt");
 FileUtils.write(child, "foo", UTF_8);
 FileUtils.write(grandChild1, "bar", UTF_8);
 FileUtils.write(grandChild2, "baz", UTF_8);
 long childSize = FileUtils2.sizeOf(child.toPath());
 assertThat(childSize).isPositive();
 long grandChild1Size = FileUtils2.sizeOf(grandChild1.toPath());
 assertThat(grandChild1Size).isPositive();
 long grandChild2Size = FileUtils2.sizeOf(grandChild2.toPath());
 assertThat(grandChild2Size).isPositive();
 assertThat(FileUtils2.sizeOf(dir.toPath()))
  .isEqualTo(childSize + grandChild1Size + grandChild2Size);
 // sanity check by comparing commons-io
 assertThat(FileUtils2.sizeOf(dir.toPath()))
  .isEqualTo(FileUtils.sizeOfDirectory(dir));
}

相关文章

FileUtils类方法