List of usage examples for org.apache.commons.io FileUtils ONE_MB
long ONE_MB
To view the source code for org.apache.commons.io FileUtils ONE_MB.
Click Source Link
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Converts the passed value into a string in Mb and returns a string * version of it./*from w w w . jav a2s.c o m*/ * * @param v The value to convert. * @return See above. */ public static String formatFileSize(long v) { if (v <= 0) return ""; String s = ""; if (v < FileUtils.ONE_KB) s = String.format("%.1f", (double) v) + " bytes"; else if (v >= FileUtils.ONE_KB && v < FileUtils.ONE_MB) s = String.format("%.1f", ((double) v / FileUtils.ONE_KB)) + " Kb"; else if (v >= FileUtils.ONE_MB && v < FileUtils.ONE_GB) s = String.format("%.1f", ((double) v / FileUtils.ONE_MB)) + " Mb"; else if (v >= FileUtils.ONE_GB) s = String.format("%.1f", ((double) v / FileUtils.ONE_GB)) + " Gb"; return s; }
From source file:org.openvpms.web.component.mail.MailEditor.java
/** * Helper to format a size./*from ww w .java2 s . c om*/ * * @param size the size, in bytes * @return the formatted size */ private String getSize(long size) { String result; if (size / FileUtils.ONE_GB > 0) { result = getSize(size, FileUtils.ONE_GB, "mail.size.GB"); } else if (size / FileUtils.ONE_MB > 0) { result = getSize(size, FileUtils.ONE_MB, "mail.size.MB"); } else if (size / FileUtils.ONE_KB > 0) { result = getSize(size, FileUtils.ONE_KB, "mail.size.KB"); } else { result = Messages.format("mail.size.bytes", size); } return result; }
From source file:org.sakaiproject.profile2.logic.ProfileImageLogicImpl.java
/** * Read a file to a byte array.// ww w . ja v a 2 s. co m * * @param file * @return byte[] if file ok, or null if its too big * @throws IOException */ private byte[] getBytesFromFile(File file) throws IOException { // Get the size of the file long length = file.length(); if (length > (ProfileConstants.MAX_IMAGE_UPLOAD_SIZE * FileUtils.ONE_MB)) { log.error("File too large: " + file.getCanonicalPath()); return null; } // return file contents return FileUtils.readFileToByteArray(file); }
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();/*from w w w. j a va 2s . c om*/ 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 ww w . jav a 2s . com 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); }