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:com.liveramp.cascading_ext.counters.Counter.java

private String prettyValue() {
    if (value == null) {
        return "null";
    }/*from   w  ww  .  j a  va2  s .c  o m*/
    if (name.contains("BYTES")) {
        return FileUtils.byteCountToDisplaySize(value);
    }
    return value.toString();
}

From source file:fr.inria.lille.repair.nopol.NoPolLauncher.java

public static List<Patch> launch(File[] sourceFile, URL[] classpath, StatementType type, String[] args) {
    System.out.println("Source files: " + Arrays.toString(sourceFile));
    System.out.println("Classpath: " + Arrays.toString(classpath));
    System.out.println("Statement type: " + type);
    System.out.println("Args: " + Arrays.toString(args));
    System.out.println("Config: " + Config.INSTANCE);
    System.out.println("Available processors (cores): " + Runtime.getRuntime().availableProcessors());

    /* Total amount of free memory available to the JVM */
    System.out.println("Free memory: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().freeMemory()));

    /* This will return Long.MAX_VALUE if there is no preset limit */
    long maxMemory = Runtime.getRuntime().maxMemory();
    /* Maximum amount of memory the JVM will attempt to use */
    System.out.println("Maximum memory: "
            + (maxMemory == Long.MAX_VALUE ? "no limit" : FileUtils.byteCountToDisplaySize(maxMemory)));

    /* Total memory currently available to the JVM */
    System.out.println("Total memory available to JVM: "
            + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory()));

    System.out.println("Java version: " + Runtime.class.getPackage().getImplementationVersion());
    System.out.println("JAVA_HOME: " + System.getenv("JAVA_HOME"));
    System.out.println("PATH: " + System.getenv("PATH"));

    long executionTime = System.currentTimeMillis();
    NoPol nopol = new NoPol(sourceFile, classpath, type);
    List<Patch> patches = null;
    try {/*from   ww  w.  j a va  2 s  . co  m*/
        if (args.length > 0) {
            patches = nopol.build(args);
        } else {
            patches = nopol.build();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        executionTime = System.currentTimeMillis() - executionTime;
        displayResult(nopol, patches, executionTime);
    }
    return patches;
}

From source file:io.github.dsheirer.util.MemoryUsageLogger.java

@Override
public String convert(ILoggingEvent iLoggingEvent) {
    //Method argument is ignored - we simply return memory usage statistics
    long allocated = Runtime.getRuntime().totalMemory();
    long free = Runtime.getRuntime().freeMemory();
    long used = allocated - free;

    int usedPercentage = (int) ((double) (used) / (double) allocated * 100.0);

    StringBuilder sb = new StringBuilder();

    sb.append("[").append(FileUtils.byteCountToDisplaySize(used).replace(" ", ""));
    sb.append("/").append(FileUtils.byteCountToDisplaySize(allocated).replace(" ", ""));
    sb.append(" ").append(usedPercentage).append("%]");

    return sb.toString();
}

From source file:com.spectralogic.dsbrowser.gui.components.physicalplacement.PhysicalPlacementTapeEntryModel.java

PhysicalPlacementTapeEntryModel(final String barcode, final String serialNumber, final String type,
        final String state, final boolean writeProtected, final long availableCapacity, final long usedCapacity,
        final String tapePartition, final String lastModified, final String ejectLabel,
        final String ejectLocation) {
    this.barcode = barcode;
    this.serialNumber = serialNumber;
    this.type = type;
    this.state = state;
    this.writeProtected = writeProtected;
    this.availableCapacity = FileUtils.byteCountToDisplaySize(availableCapacity);
    this.usedCapacity = FileUtils.byteCountToDisplaySize(usedCapacity);
    this.tapePartition = tapePartition;
    this.lastModified = lastModified;
    this.ejectLabel = ejectLabel;
    this.ejectLocation = ejectLocation;

}

From source file:com.santiagolizardo.madcommander.components.SummaryPanel.java

public void update() {
    StringBuilder buffer = new StringBuilder();

    buffer.setLength(0);/*from  w  ww.j av a 2s . co  m*/
    buffer.append(FileUtils.byteCountToDisplaySize(sizeCount)).append(" / ");
    buffer.append(FileUtils.byteCountToDisplaySize(sizeTotal));
    sizes.setText(buffer.toString());

    buffer.setLength(0);
    buffer.append(filesCount).append(" / ");
    buffer.append(filesTotal).append(" file(s)");
    files.setText(buffer.toString());

    buffer.setLength(0);
    buffer.append(dirsCount).append(" / ");
    buffer.append(dirsTotal).append(" dir(s)");
    dirs.setText(buffer.toString());
}

From source file:com.googlesource.gerrit.plugins.xdocs.formatter.ZipFormatter.java

@Override
public String format(String projectName, String path, String revision, String abbrRev, ConfigSection globalCfg,
        InputStream raw) throws IOException {
    html.startDocument().openHead().closeHead().openBody().openTable("xdoc-zip-table").appendCellHeader("name")
            .appendCellHeader("size").appendCellHeader("last modified");
    try (ZipInputStream zip = new ZipInputStream(raw)) {
        for (ZipEntry entry; (entry = zip.getNextEntry()) != null;) {
            html.openRow().appendCell(entry.getName());
            if (!entry.isDirectory()) {
                if (entry.getSize() != -1) {
                    html.appendCell(FileUtils.byteCountToDisplaySize(entry.getSize()));
                } else {
                    html.appendCell("n/a");
                }/*from   www. ja  va2  s .  c  o m*/
            } else {
                html.appendCell();
            }
            html.appendDateCell(entry.getTime()).closeRow();
        }
    }
    html.closeTable().closeBody().endDocument();

    return util.applyCss(html.toString(), NAME, projectName);
}

From source file:com.docdoku.cli.helpers.ConsoleProgressMonitorInputStream.java

public int read(byte b[]) throws IOException {
    int length = super.read(b, 0, b.length);
    totalRead += length;/*from  w  w  w.  j av  a 2 s.c o  m*/
    int percentage = (int) ((totalRead * 100.0f) / maximum);

    String percentageToPrint;
    if (percentage == 100)
        percentageToPrint = "" + percentage;
    else
        percentageToPrint = (percentage < 10) ? "  " + percentage : " " + percentage;

    if (length == -1)
        System.out.println("\r" + 100);
    else
        System.out.print("\r" + percentageToPrint + "% Total " + FileUtils.byteCountToDisplaySize(maximum) + " "
                + ROTATION[rotationChar % ROTATION.length]);

    rotationChar++;
    return length;
}

From source file:com.jaspersoft.studio.server.model.AFileResource.java

public String getHFFileSize() {
    if (file != null && file.exists())
        return FileUtils.byteCountToDisplaySize(file.length());
    return "";
}

From source file:com.jaeksoft.searchlib.ClientCatalogItem.java

public String getSizeString() {
    if (lastModifiedAndSize == null)
        return null;
    return FileUtils.byteCountToDisplaySize(lastModifiedAndSize.getSize());
}

From source file:com.tasktop.c2c.server.internal.tasks.domain.validation.AttachmentValidator.java

public void validate(Object target, Errors errors) {

    ValidationUtils.rejectIfEmpty(errors, "description", "field.required");
    ValidationUtils.rejectIfEmpty(errors, "filename", "field.required");
    ValidationUtils.rejectIfEmpty(errors, "mimeType", "field.required");

    Attachment attachment = (Attachment) target;

    if (attachment.getAttachmentData() == null || attachment.getAttachmentData().length == 0) {
        errors.rejectValue("attachmentData", "field.required");
    } else {//from  w ww  . j av a2  s. com

        int attachementSize = attachment.getAttachmentData().length;
        if (attachementSize > configuration.getMaxAttachmentSize()) {
            errors.rejectValue("attachmentData", "field.tooLarge",
                    new Object[] { FileUtils.byteCountToDisplaySize(configuration.getMaxAttachmentSize()) },
                    "Field to large");
        }
    }

    if (attachment.getFilename() != null) {
        int filenameSize = attachment.getFilename().length();
        if (filenameSize > configuration.getMaxAttachmentFilenameSize()) {
            errors.rejectValue("filename", "field.tooLarge",
                    new Object[] { configuration.getMaxAttachmentFilenameSize() }, "Field to large");
        }
    }
}