List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:de.andreasgiemza.jgeagle.panels.DeleteImagesPanel.java
private void updateSize() { long size = 0; if (Files.exists(directory)) { size = FileUtils.sizeOfDirectory(directory.toFile()); }/*w w w. ja v a 2 s . c o m*/ double sizeInMB = (double) size / 1024 / 1024; sizeLabel.setText(f.format(sizeInMB) + " MB"); }
From source file:com.thoughtworks.go.server.service.support.garage.GarageService.java
String getDirectorySize(File configRepoDir) {
return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(configRepoDir));
}
From source file:de.jwi.jfm.FileWrapper.java
public String getSize() { long l;/*from www . j a v a 2s . com*/ File file = getFile(); l = file.length(); if (file.isDirectory() && folder.isCalcRecursiveFolderSize()) { l = FileUtils.sizeOfDirectory(file); } String s = humanReadableByteCount(l, true); return s; }
From source file:it.anyplace.sync.core.cache.FileBlockCache.java
private void runCleanup() { if (size > MAX_SIZE) { logger.info("starting cleanup of cache directory, initial size = {}", FileUtils.byteCountToDisplaySize(size)); List<File> files = Lists.newArrayList(dir.listFiles()); Collections.sort(files, Ordering.natural().onResultOf(new Function<File, Long>() { @Override/*w ww . j a va2 s. c om*/ public Long apply(File input) { return input.lastModified(); } })); for (File file : Iterables.limit(files, (int) (files.size() * PERC_TO_DELETE))) { logger.debug("delete file {}", file); FileUtils.deleteQuietly(file); } size = FileUtils.sizeOfDirectory(dir); logger.info("cleanup of cache directory completed, final size = {}", FileUtils.byteCountToDisplaySize(size)); } }
From source file:com.romanenco.gitt.git.GitHelper.java
/** * Folder size in bytes./*ww w.j a va 2 s. c om*/ * * @param localPath * @return */ public static long getRepoSize(String localPath) { return FileUtils.sizeOfDirectory(new File(localPath)); }
From source file:com.playonlinux.wine.WinePrefix.java
public long getSize() { try {//from w w w . j a v a2 s.co m return FileUtils.sizeOfDirectory(this.winePrefixDirectory); } catch (IllegalArgumentException e) { logger.info("IllegalArgumentException was thrown while trying to read the directory size. Retrying...", e); return getSize(); } }
From source file:com.splunk.shuttl.testutil.TUtilsTestNG.java
private static long sizeOfDir(File realBucket) { return FileUtils.sizeOfDirectory(realBucket); }
From source file:com.thoughtworks.go.agent.UrlBasedArtifactsRepository.java
@Override public void upload(StreamConsumer console, File file, String destPath, String buildId) { if (!file.exists()) { String message = "Failed to find " + file.getAbsolutePath(); consumeLineWithPrefix(console, message); throw bomb(message); }/*w w w . ja v a2 s.c o m*/ int publishingAttempts = 0; Throwable lastException = null; while (publishingAttempts < PUBLISH_MAX_RETRIES) { File tmpDir = null; try { publishingAttempts++; tmpDir = FileUtil.createTempFolder(); File dataToUpload = new File(tmpDir, file.getName() + ".zip"); zipUtil.zip(file, dataToUpload, Deflater.BEST_SPEED); long size; if (file.isDirectory()) { size = FileUtils.sizeOfDirectory(file); } else { size = file.length(); } consumeLineWithPrefix(console, format("Uploading artifacts from %s to %s", file.getAbsolutePath(), getDestPath(destPath))); String normalizedDestPath = normalizePath(destPath); String url = getUploadUrl(buildId, normalizedDestPath, publishingAttempts); int statusCode = httpService.upload(url, size, dataToUpload, artifactChecksums(file, normalizedDestPath)); if (statusCode == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE) { String message = format( "Artifact upload for file %s (Size: %s) was denied by the server. This usually happens when server runs out of disk space.", file.getAbsolutePath(), size); consumeLineWithPrefix(console, message); LOGGER.error( "[Artifact Upload] Artifact upload was denied by the server. This usually happens when server runs out of disk space."); publishingAttempts = PUBLISH_MAX_RETRIES; throw bomb(message + ". HTTP return code is " + statusCode); } if (statusCode < HttpServletResponse.SC_OK || statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES) { throw bomb( "Failed to upload " + file.getAbsolutePath() + ". HTTP return code is " + statusCode); } return; } catch (Throwable e) { String message = "Failed to upload " + file.getAbsolutePath(); LOGGER.error(message, e); consumeLineWithPrefix(console, message); lastException = e; } finally { FileUtil.deleteFolder(tmpDir); } } if (lastException != null) { throw new RuntimeException(lastException); } }
From source file:com.linkedin.pinot.core.segment.store.SegmentLocalFSDirectory.java
@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 {//from w ww. j av a 2 s. co m return FileUtils.sizeOfDirectory(segmentDirectory.toPath().toFile()); } catch (IllegalArgumentException e) { LOGGER.error("Failed to read disk size for direcotry: ", 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(); long size = 0L; for (File file : files) { if (file.isFile()) { size += file.length(); } } return size; } }
From source file:com.talis.entity.db.EntityDatabasePerfTestBase.java
@Test public void benchmarkAccessSingleGraph() throws EntityDatabaseException { System.out.println("Accessing Single Graph"); int graphs = 100000; int stmtsPerGraph = 20; long start = System.currentTimeMillis(); db.begin();/*from w w w .j av a 2 s .c o m*/ for (int i = 0; i < graphs; i++) { Node thisGraph = Node.createURI(graph.getURI() + "_" + i); db.put(subject, thisGraph, getQuads(thisGraph, subject, stmtsPerGraph)); } db.commit(); System.out.println(String.format("Populated %s graphs (%s total statements) in %s ms", graphs, graphs * stmtsPerGraph, (System.currentTimeMillis() - start))); int iter = Math.round(graphs / 4); Random r = new Random(); start = System.currentTimeMillis(); for (int i = 0; i < iter; i++) { Node thisGraph = Node.createURI(graph.getURI() + "_" + r.nextInt(graphs)); db.getGraph(thisGraph); } long end = System.currentTimeMillis(); long duration = end - start; System.out.println(String.format("Iterations: %s, Total: %s, PerOp: %s", iter, duration, (double) ((double) duration / (double) iter))); long size = FileUtils.sizeOfDirectory(tmpDir.getRoot()); System.out.println(String.format("Size on disk : %s (%s)", FileUtils.byteCountToDisplaySize(size), size)); }