Example usage for org.apache.commons.io FileUtils byteCountToDisplaySize

List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils byteCountToDisplaySize.

Prototype

public static String byteCountToDisplaySize(long size) 

Source Link

Document

Returns a human-readable version of the file size, where the input represents a specific number of bytes.

Usage

From source file:org.sonar.batch.bootstrap.PreviewDatabase.java

private void downloadDatabase(File toFile, int readTimeoutMillis) {
    String projectKey = null;//from  w  w w.  j a v  a 2s .  c o m
    try {
        projectKey = settings.getString(CoreProperties.PROJECT_KEY_PROPERTY);
        String branch = settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY);
        if (StringUtils.isNotBlank(branch)) {
            projectKey = String.format("%s:%s", projectKey, branch);
        }
        if (StringUtils.isBlank(projectKey)) {
            server.download("/batch_bootstrap/db", toFile, readTimeoutMillis);
        } else {
            server.download("/batch_bootstrap/db?project=" + projectKey, toFile, readTimeoutMillis);
        }
        LOG.debug("Dry Run database size: {}", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toFile)));
    } catch (SonarException e) {
        handleException(readTimeoutMillis, projectKey, e);
        throw e;
    }
}

From source file:org.sonar.batch.report.ReportPublisher.java

private File generateReportFile() {
    try {//from w w w .ja  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.microbenchmark.SerializationBenchmarkTest.java

private String sizeOf(File file) {
    return FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(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 ww .j  a  v  a  2s . com*/
    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());//ww  w .  jav a  2 s  . c o  m
    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.sonar.server.computation.step.ExtractReportStep.java

@Override
public void execute() {
    File dir = tempFolder.newDir();
    File zip = reportFiles.fileForUuid(task.getUuid());
    try {/*from   w  w w  .j a v a 2  s  . c  om*/
        ZipUtils.unzip(zip, dir);
        reportDirectoryHolder.setDirectory(dir);
        LOG.info("Analysis report extracted | compressedSize={}",
                FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(zip)));
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Fail to unzip %s into %s", zip, dir), e);
    }
}

From source file:org.sonar.server.computation.step.ParseReportStep.java

private void extractReport(AnalysisReportDto report, File toDir) {
    long startTime = System.currentTimeMillis();
    DbSession session = dbClient.openSession(false);
    try {/*w  w  w  .jav a  2s.  com*/
        dbClient.analysisReportDao().selectAndDecompressToDir(session, report.getId(), toDir);
    } finally {
        MyBatis.closeQuietly(session);
    }
    long stopTime = System.currentTimeMillis();
    LOG.info(String.format("Report extracted in %dms | uncompressed size=%s | project=%s", stopTime - startTime,
            FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toDir)), report.getProjectKey()));
}

From source file:org.sonar.server.computation.step.ReportExtractionStep.java

@Override
public void execute() {
    File dir = tempFolder.newDir();
    try {/*from   w  w  w  . ja v  a  2 s .com*/
        Profiler profiler = Profiler.createIfDebug(LOG).start();
        ZipUtils.unzip(item.zipFile, dir);
        if (profiler.isDebugEnabled()) {
            String message = String.format("Report extracted | size=%s | project=%s",
                    FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(dir)), item.dto.getProjectKey());
            profiler.stopDebug(message);
        }
        reportDirectoryHolder.setDirectory(dir);
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Fail to unzip %s into %s", item.zipFile, dir), e);
    }
}

From source file:org.stem.db.FatFileAllocator.java

public static void allocateDirectory(String directoryPath, long sizeInMB, long maxSize, boolean mark)
        throws IOException {
    long started = System.currentTimeMillis();
    File dir = BBUtils.getDirectory(directoryPath);
    // TODO: empty check

    long allocated = sizeInMB * 1024 * 1024;
    int fatFileIndex = 0;

    //while (FileSystemUtils.freeSpaceKb(directoryPath)/1024 > sizeInMB)
    while (maxSize >= allocated) {
        String fatFilePath = dir.getAbsolutePath() + File.separator + buildFileName(fatFileIndex);
        allocateFile(fatFilePath, sizeInMB, mark);
        allocated += sizeInMB * 1024 * 1024;
        fatFileIndex++;/*from  w  w  w. j av  a2s.c o m*/
    }
    int totalAllocated = fatFileIndex;
    if (0 == totalAllocated)
        throw new RuntimeException(
                "Can't preallocate, maybe there is no free space on the device " + directoryPath);

    logger.debug("Directory {} ({}, {} files) was allocated in {} ms", directoryPath,
            FileUtils.byteCountToDisplaySize(maxSize), fatFileIndex, System.currentTimeMillis() - started);

}

From source file:org.stem.ProtocolTest.java

@Test
@Ignore // TODO: it's ignored because it's ran endlessly
public void testStorageNodeWritePerformance() throws Exception {
    StorageNodeClient client = new StorageNodeClient(host, port);
    client.start();// w w  w.  j a v a2 s . c om

    byte[] blob = TestUtils.generateRandomBlob(65536);
    byte[] key = DigestUtils.md5(blob);
    UUID disk = Layout.getInstance().getMountPoints().keySet().iterator().next();
    WriteBlobMessage op = new WriteBlobMessage();
    op.disk = disk;
    op.key = key;
    op.blob = blob;

    long start, duration;
    long i = 0;
    start = System.nanoTime();
    while (true) {
        i++;
        Message.Response resp = client.execute(op);
        if (i % 1000 == 0) {
            duration = System.nanoTime() - start;

            long rps = i * 1000000000 / duration;
            System.out.println(
                    String.format("%s req/s, %s/s", rps, FileUtils.byteCountToDisplaySize(rps * blob.length)));
            start = System.nanoTime();
            i = 0;
        }
    }
}