List of usage examples for org.apache.commons.io FileUtils sizeOfDirectory
public static long sizeOfDirectory(File directory)
From source file:org.silverpeas.core.silverstatistics.volume.service.DirectorySizeComputer.java
@Override public DirectoryStats call() throws Exception { long size = 0L; try {/*from ww w .java2s .c o m*/ size = FileUtils.sizeOfDirectory(directory); } catch (Exception e) { // preventing bug http://tracker.silverpeas.org/issues/5340 SilverTrace.error("silverstatistics", "DirectorySizeComputer.call", "root.EX_CANT_READ_FILE", "Directory : " + directory.getAbsolutePath(), e); } return new DirectoryStats(directory.getName(), size, 0L); }
From source file:org.sonar.batch.report.ReportPublisher.java
private File generateReportFile() { try {// w w w . j a v a 2 s . c o m 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))); startTime = System.currentTimeMillis(); File reportZip = temp.newFile("batch-report", ".zip"); ZipUtils.zipDir(reportDir, reportZip); stopTime = System.currentTimeMillis(); LOG.info("Analysis reports 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); } }
From source file:org.sonar.server.benchmark.IssueIndexBenchmarkTest.java
private void benchmarkIssueIndexing() { LOGGER.info("Indexing issues"); IssueIterator issues = new IssueIterator(PROJECTS, FILES_PER_PROJECT, ISSUES_PER_FILE); ProgressTask progressTask = new ProgressTask(LOGGER, "issues", issues.count()); Timer timer = new Timer("IssuesIndex"); timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS); long start = System.currentTimeMillis(); tester.get(IssueIndexer.class).index(issues); timer.cancel();// w w w . j a va2 s . c o m long period = System.currentTimeMillis() - start; long throughputPerSecond = 1000 * issues.count.get() / period; LOGGER.info(String.format("%d issues indexed in %d ms (%d docs/second)", issues.count.get(), period, throughputPerSecond)); benchmark.expectAround("Throughput to index issues", throughputPerSecond, 6500, Benchmark.DEFAULT_ERROR_MARGIN_PERCENTS); // be sure that physical files do not evolve during estimation of size tester.get(EsClient.class).prepareOptimize("issues").get(); long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()); LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize))); benchmark.expectBetween("ES dir size (b)", dirSize, 200L * FileUtils.ONE_MB, 420L * FileUtils.ONE_MB); }
From source file:org.sonar.server.benchmark.SourceIndexBenchmarkTest.java
private void benchmarkIndexing() { LOGGER.info("Indexing source lines"); SourceIterator files = new SourceIterator(FILES, LINES_PER_FILE); ProgressTask progressTask = new ProgressTask(LOGGER, "files of " + LINES_PER_FILE + " lines", files.count());/*from www . j ava2s . c om*/ Timer timer = new Timer("SourceIndexer"); timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS); long start = System.currentTimeMillis(); tester.get(SourceLineIndexer.class).index(files); long end = System.currentTimeMillis(); timer.cancel(); long period = end - start; long nbLines = files.count.get() * LINES_PER_FILE; long throughputPerSecond = 1000L * nbLines / period; LOGGER.info( String.format("%d lines indexed in %d ms (%d docs/second)", nbLines, period, throughputPerSecond)); benchmark.expectBetween("Throughput to index source lines", throughputPerSecond, 6000L, 6400L); // be sure that physical files do not evolve during estimation of size tester.get(EsClient.class).prepareOptimize(SourceLineIndexDefinition.INDEX).get(); long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()); LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize))); benchmark.expectBetween("ES dir size (b)", dirSize, 103L * FileUtils.ONE_MB, 109L * FileUtils.ONE_MB); }
From source file:org.wise.vle.utils.FileManager.java
/** * Returns the size in bytes of all of the files in the specified path/dirname * * @param path the path to the project folder * @return the size of the folder in bytes as a string *///w w w. j ava2 s . co m public static String getProjectSize(String path) { if (path == null) { return "No project path specified"; } else { File projectDir = new File(path); if (projectDir.exists()) { if (projectDir.isDirectory()) { long sizeOfDirectory = FileUtils.sizeOfDirectory(projectDir); return String.valueOf(sizeOfDirectory); } else { return "0"; } } else { return "Given project path does not exist."; } } }
From source file:org.wise.vle.web.AssetManager.java
/** * Returns the size in bytes of all of the files in the specified path/dirname * //w ww . jav a2 s . c om * @param <code>String</code> folderPath the path to the folder as a string * @return <code>String</code> size of all files in assets folder in bytes */ public static String getFolderSize(String folderPath) { String folderSize = ""; if (folderPath != null) { //get a handle on the folder File folder = new File(folderPath); //make sure the folder exists and is a folder if (folder.exists() && folder.isDirectory()) { //get the size of the folder long sizeOfDirectory = FileUtils.sizeOfDirectory(folder); //get the folder size as a string folderSize = String.valueOf(sizeOfDirectory); } else { //folder does not exist or is not a folder folderSize = "Given folder path does not exist or is not a folder."; } } else { //folder path is null folderSize = "Folder path not provided."; } return folderSize; }
From source file:simpleserver.thread.AutoFreeSpaceChecker.java
public void check(boolean beforeBackup) { try {/* w w w . jav a 2s .co m*/ long neededSizeKb = 0; if (beforeBackup) { neededSizeKb += Math.round(FileUtils.sizeOfDirectory(server.getWorldDirectory()) / 1024) * 2; } else { neededSizeKb = 50 * 1024; } long freeSpaceKb = FileSystemUtils.freeSpaceKb(); if (freeSpaceKb < neededSizeKb) { println("Warning: You have only " + Math.round(freeSpaceKb / 1024) + " MB free space in this drive!"); println("Trying to delete old backups..."); int filesDeleted = 0; while (FileSystemUtils.freeSpaceKb() < neededSizeKb) { File firstCreatedFile = AutoBackup.oldestBackup(); if (firstCreatedFile != null) { println("Deleting: " + firstCreatedFile.getPath()); firstCreatedFile.delete(); filesDeleted++; } else { println("No backups found..."); return; } } if (filesDeleted > 1) { println("Deleted " + filesDeleted + " backup archives."); } else { println("Deleted 1 backup archive."); } } } catch (IOException e) { println(e); println("Free Space Checker Failed!"); } catch (IllegalArgumentException e) { println(e); println("Backup space calculation failed because of a was file deleted during action. Trying again later."); } }
From source file:uk.sipperfly.ui.Exactly.java
private void btnTransferFilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTransferFilesActionPerformed if (this.MetadataReminder == 1) { UpdateResult("Save Metadata before starting Transfer.", 1); return;//from w ww. j a va 2 s . com } if (!this.setDropLocation()) { this.btnTransferFiles.setEnabled(true); this.btnCancel.setVisible(false); return; } CommonUtil commonUtil = new CommonUtil(); Boolean isSelected = false; List<String> directories = new ArrayList<String>(); directories = this.uIManager.getInputDirectories(); directories.add(editInputDir.getText()); long size = 0; ConfigurationsRepo configRepo = new ConfigurationsRepo(); Configurations config = configRepo.getOneOrCreateOne(); for (String directory : directories) { if (!directory.isEmpty()) { isSelected = true; File f = new File(directory); if (!f.exists()) { UpdateResult("Must choose a valid input folder(s).", 1); return; } else { if (f.isFile()) { size = size + FileUtils.sizeOf(f); boolean ignore = commonUtil.checkIgnoreFiles(f.getName(), config.getFilters()); if (!ignore) { this.totalFiles = this.totalFiles + 1; } } else { size = size + FileUtils.sizeOfDirectory(f); this.totalFiles = this.totalFiles + commonUtil.countFilesInDirectory(f, config.getFilters()); } } } } this.uploadedFiles = this.totalFiles; size = commonUtil.convertBytestoGB(size); if (size > 200) { UpdateResult("Directories size exceed from 200 GB.", 1); return; } if (!isSelected) { UpdateResult("Must choose an input folder.", 1); return; } if (this.metadateUpdated == 0) { this.warning.setVisible(true); } else { this.jButton14ActionPerformed(evt); } }