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.gradle.api.changedetection.state.DirectoryState.java

public String toString() {
    final StringBuilder strBuilder = new StringBuilder();

    strBuilder.append("[");
    strBuilder.append(level);/* w ww. j  av a 2 s  .co m*/
    strBuilder.append("] ");
    strBuilder.append(relativePath);
    strBuilder.append(" : ");
    strBuilder.append(digest);
    strBuilder.append(" : ");
    strBuilder.append(FileUtils.byteCountToDisplaySize(size));

    return strBuilder.toString();
}

From source file:org.gradle.cache.internal.FixedSizeOldestCacheCleanup.java

List<File> findFilesToDelete(final PersistentCache persistentCache, File[] filesEligibleForCleanup) {
    Arrays.sort(filesEligibleForCleanup, NEWEST_FIRST);

    // All sizes are in bytes
    long totalSize = 0;
    long targetSize = targetSizeInMB * 1024 * 1024;
    final List<File> filesForDeletion = Lists.newArrayList();

    for (File file : filesEligibleForCleanup) {
        long size = file.length();
        totalSize += size;//from w  ww.  ja  v a  2 s. co m

        if (totalSize > targetSize) {
            filesForDeletion.add(file);
        }
    }

    LOGGER.info("{} consuming {} MB (target: {} MB).", persistentCache,
            FileUtils.byteCountToDisplaySize(totalSize), targetSizeInMB);

    return filesForDeletion;
}

From source file:org.gradle.cache.internal.FixedSizeOldestCacheCleanup.java

void cleanupFiles(final PersistentCache persistentCache, final List<File> filesForDeletion) {
    // Need to remove some files
    long removedSize = deleteFiles(filesForDeletion);
    LOGGER.info("{} removing {} cache entries ({} MB reclaimed).", persistentCache, filesForDeletion.size(),
            FileUtils.byteCountToDisplaySize(removedSize));
}

From source file:org.gradle.caching.local.internal.DirectoryBuildCacheServiceFactory.java

@Override
public BuildCacheService createBuildCacheService(DirectoryBuildCache configuration, Describer describer) {
    Object cacheDirectory = configuration.getDirectory();
    File target;/* w  w w  . ja v a2  s.com*/
    if (cacheDirectory != null) {
        target = resolver.resolve(cacheDirectory);
    } else {
        target = cacheScopeMapping.getBaseDirectory(null, BUILD_CACHE_KEY, VersionStrategy.SharedCache);
    }
    checkDirectory(target);

    long targetSizeInMB = configuration.getTargetSizeInMB();
    String humanReadableCacheSize = FileUtils.byteCountToDisplaySize(targetSizeInMB * 1024 * 1024);
    describer.type(DIRECTORY_BUILD_CACHE_TYPE).config("location", target.getAbsolutePath()).config("targetSize",
            humanReadableCacheSize);

    PathKeyFileStore fileStore = fileStoreFactory.createFileStore(target);
    PersistentCache persistentCache = cacheRepository.cache(target)
            .withCleanup(new FixedSizeOldestCacheCleanup(buildOperationExecutor, targetSizeInMB,
                    BuildCacheTempFileStore.PARTIAL_FILE_SUFFIX))
            .withDisplayName("Build cache").withLockOptions(mode(None))
            .withCrossVersionCache(CacheBuilder.LockTarget.DefaultTarget).open();
    BuildCacheTempFileStore tempFileStore = new DefaultBuildCacheTempFileStore(target,
            BuildCacheTempFileStore.PARTIAL_FILE_SUFFIX);

    return new DirectoryBuildCacheService(fileStore, persistentCache, tempFileStore, FAILED_READ_SUFFIX);
}

From source file:org.italiangrid.storm.webdav.metrics.StormMetricsReporter.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from w w  w .  ja  va 2  s .c o  m
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters,
        SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters,
        SortedMap<String, Timer> timers) {

    Gauge<Double> heapUsage = gauges.get("jvm.memory.heap.usage");
    Gauge<Long> heapUsed = gauges.get("jvm.memory.heap.used");

    Timer handlerDispatches = timers.get("storm.http.handler.dispatches");
    final Snapshot snapshot = handlerDispatches.getSnapshot();

    Long lastMinuteCount = null;

    if (lastCountValue != null) {
        lastMinuteCount = handlerDispatches.getCount() - lastCountValue;
    }

    lastCountValue = handlerDispatches.getCount();

    logger.info(
            "Heap[usage={}, used={}] Requests[m1_count={}, count={}, max={}, min={}, mean={}, mean_rate={}, m1_rate={}, m5_rate={}, m15_rate={}] Duration_units={}, Rate_units={}",
            heapUsage.getValue(), FileUtils.byteCountToDisplaySize(heapUsed.getValue()), lastMinuteCount,
            handlerDispatches.getCount(), convertDuration(snapshot.getMax()),
            convertDuration(snapshot.getMin()), convertDuration(snapshot.getMean()),
            convertRate(handlerDispatches.getMeanRate()), convertRate(handlerDispatches.getOneMinuteRate()),
            convertRate(handlerDispatches.getFiveMinuteRate()),
            convertRate(handlerDispatches.getFifteenMinuteRate()), getDurationUnit(), getRateUnit());

}

From source file:org.jahia.taglibs.jcr.node.JCRTagUtils.java

public static String humanReadableFileLength(JCRNodeWrapper node) {
    return FileUtils.byteCountToDisplaySize(node.getFileContent().getContentLength());
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionRecordingImpl.java

public String getDisplayRecordingSize() {
    return FileUtils.byteCountToDisplaySize(this.recordingSize);
}

From source file:org.jesterj.ingest.processors.SetReadableFileSize.java

@Override
public Document[] processDocument(Document document) {

    String val = document.getFirstValue(getInputField());
    if (StringUtils.isNotBlank(val)) {
        long lFileSize = Long.parseLong(val);

        String readableFileSize = FileUtils.byteCountToDisplaySize(lFileSize);

        if (StringUtils.isNotBlank(getNumericAndUnitsField())) {
            document.put(getNumericAndUnitsField(), readableFileSize);
        }/*from   w  w  w.j  av a  2 s. c o  m*/
        String[] parts = readableFileSize.split(" ");
        if (StringUtils.isNotBlank(getUnitsField())) {
            document.put(getUnitsField(), parts[1]);
        }
        if (StringUtils.isNotBlank(getNumericField())) {
            document.put(getNumericField(), parts[0]);
        }
    }

    return new Document[] { document };
}

From source file:org.jimcat.gui.perspective.boards.cards.Card.java

/**
 * update shown metadata//from  w  ww.  j a v  a  2s  . com
 * 
 * @param metadata
 */
private void updateMetadata(ImageMetadata metadata) {
    if (metadata != null) {
        // Dimension
        dimension.setText(metadata.getWidth() + "x" + metadata.getHeight());
        // image size
        size.setText(FileUtils.byteCountToDisplaySize(metadata.getSize()));
        // location
        File location = metadata.getPath();
        String strLocation = "";
        if (location != null) {
            strLocation = location.getParent();
        }
        path.setText(formatPath(location));
        path.setToolTipText(strLocation);
    } else {
        dimension.setText("");
        size.setText("");
        path.setText("");
        path.setToolTipText("");
    }
}

From source file:org.knime.knip.base.data.ObjectRepository.java

private ObjectRepository() {
    m_memoryWarningSystem.setPercentageUsageThreshold(0.7);
    m_memoryWarningSystem.registerListener(new MemoryWarningSystem.MemoryWarningListener() {

        @Override/*from  w  w w .j  a  v a 2 s. c o m*/
        public void memoryUsageLow(final long usedMemory, final long maxMemory) {
            LOGGER.debug("Low memory encountered in KNIP. Used memory: "
                    + FileUtils.byteCountToDisplaySize(usedMemory) + "; maximum memory: "
                    + FileUtils.byteCountToDisplaySize(maxMemory) + ".");
            // run in separate thread so that it can be debugged and we don't mess around with system threads
            new Thread(new Runnable() {
                @Override
                public void run() {
                    synchronized (CACHED_OBJECTS) {
                        CACHED_OBJECTS.clear();
                    }
                }
            }, "KNIP-Memory-Cleaner").start();
        }
    });
}