public CachedTableInfo(String cachePath) { this.cachePath = cachePath; this.dbSize = FileUtils.sizeOfDirectory(new File(cachePath)); }
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();
private String getConfigRepoDisplaySize() { return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(workingDir)); }
public long getTotalCacheSize() { return FileUtils.sizeOfDirectory(new File(getCacheBasePath(config))); }
return FileUtils.sizeOfDirectory(segmentDirectory.toPath().toFile()); } catch (IllegalArgumentException e) { LOGGER.error("Failed to read disk size for direcotry: ", segmentDirectory.getAbsolutePath());
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; }
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); } }
@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"); }
@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); }
@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); }
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(); }
size = FileUtils.sizeOfDirectory(source); } else { size = source.length();
@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); }
size = FileUtils.sizeOfDirectory(file); } else { size = file.length();
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);
final long srcSize = FileUtils.sizeOfDirectory(srcDir); assertTrue("Size > 0", srcSize > 0); assertEquals(srcSize, FileUtils.sizeOfDirectory(destDir)); assertTrue(new File(destDir, "sub/A.txt").exists());
@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)); }
@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); }
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);
@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)); }