/** * Returns a human-readable version of the file size, where the input represents a specific number of bytes. * <p> * If the size is over 1GB, the size is returned as the number of whole GB, i.e. the size is rounded down to the * nearest GB boundary. * </p> * <p> * Similarly for the 1MB and 1KB boundaries. * </p> * * @param size the number of bytes * @return a human-readable display value (includes units - EB, PB, TB, GB, MB, KB or bytes) * @see <a href="https://issues.apache.org/jira/browse/IO-226">IO-226 - should the rounding be changed?</a> */ // See https://issues.apache.org/jira/browse/IO-226 - should the rounding be changed? public static String byteCountToDisplaySize(final long size) { return byteCountToDisplaySize(BigInteger.valueOf(size)); }
private String getConfigRepoDisplaySize() { return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(workingDir)); }
@Override public void run() { if (jarNumbers > 0) { String info = getInfo(currentLine); String sizeWithUnit = byteCountToDisplaySize(new Double(sizeInKb * 1000).longValue()); String status = String.format("%d jar%s, %s downloaded at %s %s", jarNumbers, getPluralFormWhenNumberOfJarGreaterThanOne(), sizeWithUnit, speed, info); widget.setValue(status + "</br>" + formatCurrentLine()); widget.setDomClasses(asList("text-ellipsis")); } } }, 0, PERIOD);
public String availableDiskSpace() { File artifactsDir = artifactsDirHolder.getArtifactsDir(); return FileUtils.byteCountToDisplaySize(artifactsDir.getUsableSpace()); } }
private File generateReportFile() { try { 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.toFile()))); startTime = System.currentTimeMillis(); File reportZip = temp.newFile("scanner-report", ".zip"); ZipUtils.zipDir(reportDir.toFile(), reportZip); stopTime = System.currentTimeMillis(); LOG.info("Analysis report 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); } }
@SuppressWarnings("NumericOverflow") @Test public void testByteCountToDisplaySizeLong() { assertEquals(FileUtils.byteCountToDisplaySize(0), "0 bytes"); assertEquals(FileUtils.byteCountToDisplaySize(1), "1 bytes"); assertEquals(FileUtils.byteCountToDisplaySize(1023), "1023 bytes"); assertEquals(FileUtils.byteCountToDisplaySize(1024), "1 KB"); assertEquals(FileUtils.byteCountToDisplaySize(1025), "1 KB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1023), "1023 KB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024), "1 MB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1025), "1 MB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1023), "1023 MB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024), "1 GB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1025), "1 GB"); assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 2), "2 GB"); assertEquals(FileUtils.byteCountToDisplaySize(1024 * 1024 * 1024 * 2 - 1), "1 GB"); assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 1024), "1 TB"); assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 1024 * 1024), "1 PB"); assertEquals(FileUtils.byteCountToDisplaySize(1024L * 1024 * 1024 * 1024 * 1024 * 1024), "1 EB"); assertEquals(FileUtils.byteCountToDisplaySize(Long.MAX_VALUE), "7 EB"); // Other MAX_VALUEs assertEquals(FileUtils.byteCountToDisplaySize(Character.MAX_VALUE), "63 KB"); assertEquals(FileUtils.byteCountToDisplaySize(Short.MAX_VALUE), "31 KB"); assertEquals(FileUtils.byteCountToDisplaySize(Integer.MAX_VALUE), "1 GB"); }
final BigInteger PB1 = TB1.multiply(KB1); final BigInteger EB1 = PB1.multiply(KB1); assertEquals(FileUtils.byteCountToDisplaySize(BigInteger.ZERO), "0 bytes"); assertEquals(FileUtils.byteCountToDisplaySize(BigInteger.ONE), "1 bytes"); assertEquals(FileUtils.byteCountToDisplaySize(b1023), "1023 bytes"); assertEquals(FileUtils.byteCountToDisplaySize(KB1), "1 KB"); assertEquals(FileUtils.byteCountToDisplaySize(b1025), "1 KB"); assertEquals(FileUtils.byteCountToDisplaySize(MB1.subtract(BigInteger.ONE)), "1023 KB"); assertEquals(FileUtils.byteCountToDisplaySize(MB1), "1 MB"); assertEquals(FileUtils.byteCountToDisplaySize(MB1.add(BigInteger.ONE)), "1 MB"); assertEquals(FileUtils.byteCountToDisplaySize(GB1.subtract(BigInteger.ONE)), "1023 MB"); assertEquals(FileUtils.byteCountToDisplaySize(GB1), "1 GB"); assertEquals(FileUtils.byteCountToDisplaySize(GB1.add(BigInteger.ONE)), "1 GB"); assertEquals(FileUtils.byteCountToDisplaySize(GB2), "2 GB"); assertEquals(FileUtils.byteCountToDisplaySize(GB2.subtract(BigInteger.ONE)), "1 GB"); assertEquals(FileUtils.byteCountToDisplaySize(TB1), "1 TB"); assertEquals(FileUtils.byteCountToDisplaySize(PB1), "1 PB"); assertEquals(FileUtils.byteCountToDisplaySize(EB1), "1 EB"); assertEquals(FileUtils.byteCountToDisplaySize(Long.MAX_VALUE), "7 EB"); assertEquals(FileUtils.byteCountToDisplaySize(BigInteger.valueOf(Character.MAX_VALUE)), "63 KB"); assertEquals(FileUtils.byteCountToDisplaySize(BigInteger.valueOf(Short.MAX_VALUE)), "31 KB"); assertEquals(FileUtils.byteCountToDisplaySize(BigInteger.valueOf(Integer.MAX_VALUE)), "1 GB");
private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) { IndicesStatsResponse indicesStats = esClient.prepareStats().all().get(); for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) { String prefix = "Index " + indexStats.getKey() + " - "; setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount()); setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length); setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes())); } } }
@Override public void execute(ComputationStep.Context context) { try (DbSession dbSession = dbClient.openSession(false)) { Optional<CeTaskInputDao.DataStream> opt = dbClient.ceTaskInputDao().selectData(dbSession, task.getUuid()); if (opt.isPresent()) { File unzippedDir = tempFolder.newDir(); try (CeTaskInputDao.DataStream reportStream = opt.get(); InputStream zipStream = new BufferedInputStream(reportStream.getInputStream())) { ZipUtils.unzip(zipStream, unzippedDir); } catch (IOException e) { throw new IllegalStateException("Fail to extract report " + task.getUuid() + " from database", e); } reportDirectoryHolder.setDirectory(unzippedDir); if (LOGGER.isDebugEnabled()) { // size is not added to context statistics because computation // can take time. It's enabled only if log level is DEBUG. try { String dirSize = FileUtils.byteCountToDisplaySize(FileUtils2.sizeOf(unzippedDir.toPath())); LOGGER.debug("Analysis report is {} uncompressed", dirSize); } catch (IOException e) { LOGGER.warn("Fail to compute size of directory " + unzippedDir, e); } } } else { throw MessageException.of("Analysis report " + task.getUuid() + " is missing in database"); } } }
public static void toProtobuf(NodeStats stats, ProtobufSystemInfo.Section.Builder protobuf) { setAttribute(protobuf, "CPU Usage (%)", stats.getProcess().getCpu().getPercent()); setAttribute(protobuf, "Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().getBytes())); setAttribute(protobuf, "Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes())); setAttribute(protobuf, "Open File Descriptors", stats.getProcess().getOpenFileDescriptors()); setAttribute(protobuf, "Max File Descriptors", stats.getProcess().getMaxFileDescriptors()); setAttribute(protobuf, "Spinning", stats.getFs().getTotal().getSpins()); setAttribute(protobuf, "JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPercent())); setAttribute(protobuf, "JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().getBytes())); setAttribute(protobuf, "JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().getBytes())); setAttribute(protobuf, "JVM Non Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getNonHeapUsed().getBytes())); setAttribute(protobuf, "JVM Threads", stats.getJvm().getThreads().getCount()); setAttribute(protobuf, "Field Data Memory", byteCountToDisplaySize(stats.getIndices().getFieldData().getMemorySizeInBytes())); setAttribute(protobuf, "Field Data Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getLimit())); setAttribute(protobuf, "Field Data Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated())); setAttribute(protobuf, "Request Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getLimit())); setAttribute(protobuf, "Request Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getEstimated())); setAttribute(protobuf, "Query Cache Memory", byteCountToDisplaySize(stats.getIndices().getQueryCache().getMemorySizeInBytes())); setAttribute(protobuf, "Request Cache Memory", byteCountToDisplaySize(stats.getIndices().getRequestCache().getMemorySizeInBytes())); }
@Override public String getStringifiedValue() { if (value == null) { return "null"; } return FileUtils.byteCountToDisplaySize(value.longValue()); } }
@Override public String getTextValue(Number item) { return (item != null) ? FileUtils.byteCountToDisplaySize(item.longValue()) : ""; }
@Override public Map<String, Object> getMetrics() { Map<String, Object> metrics = InsertionOrderUtil.newMap(); // NOTE: the unit of rocksdb mem property is kb metrics.put(MEM_USED, this.getMemUsed() / Bytes.BASE); metrics.put(MEM_UNIT, "MB"); String size = FileUtils.byteCountToDisplaySize(this.getDataSize()); metrics.put(DATA_SIZE, size); return metrics; }
private void setFileProperties(File file) { fileLabel.setText(file.getAbsolutePath()); size.setText(FileUtils.byteCountToDisplaySize(file.length())); modified.setText(FORMATTER.format(file.lastModified())); }
if (fileSize > nextLog) { System.err.print("\r" + ansi().eraseLine()); System.err.print(FileUtils.byteCountToDisplaySize(fileSize)); if (maxLength > 0) { System.err.print(" [");
ourLog.info("Successfully Loaded example pack ({})", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(inputFile))); IOUtils.closeQuietly(result.getEntity().getContent());
ourLog.info("Final bundle: {}", FileUtils.byteCountToDisplaySize(encoded.length()));
ourLog.info("Trimming contents of resource: {} - From {} to {}", nextFile, FileUtils.byteCountToDisplaySize(inputString.length()), FileUtils.byteCountToDisplaySize(outputString.length())); myByteCount += (inputString.length() - outputString.length()); myFileCount++;
ourLog.info("Trimmed {} bytes", FileUtils.byteCountToDisplaySize(byteCount));
System.getProperty("javafx.runtime.version"))); Label memory = new Label(DefaultI18nContext.getInstance().i18n("Max memory {0}", FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory()))); Button copyButton = new Button(DefaultI18nContext.getInstance().i18n("Copy to clipboard")); FontAwesomeIconFactory.get().setIcon(copyButton, FontAwesomeIcon.COPY);