List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:com.isomorphic.maven.util.LoggingCountingOutputStream.java
@Override protected void afterWrite(final int bytesWritten) throws IOException { super.afterWrite(bytesWritten); final long byteCount = getByteCount(); final double progress = ((double) byteCount / (double) expectedByteCount) * 100.0; snapshotBytes += bytesWritten;/* w w w . ja v a 2s .co m*/ // Lets grab the number of bytes written over the last second and use that as our // bytesPerSecond gauge giving the user an indication of speed. if (System.currentTimeMillis() - snapshotStart >= 1000) { snapshotStart = System.currentTimeMillis(); bytesPerSecond = snapshotBytes; snapshotBytes = 0; } // Using \r in this print out will cause the console to render this line of text on the // same line in order to avoid console spam. System.out.print("\r" + StringUtils.rightPad(FileUtils.byteCountToDisplaySize(byteCount) + " / " + FileUtils.byteCountToDisplaySize(expectedByteCount) + " (" + FileUtils.byteCountToDisplaySize(bytesPerSecond) + "/second) " + String.format("%.1f%%", progress), 60, " ")); if (progress >= 100.0) { System.out.println("Done!"); } }
From source file:eu.over9000.skadi.ui.dialogs.UpdateAvailableDialog.java
public UpdateAvailableDialog(RemoteVersionResult newVersion) { super(AlertType.INFORMATION, null, UPDATE_BUTTON_TYPE, IGNORE_BUTTON_TYPE); this.setTitle("Update available"); this.setHeaderText(newVersion.getVersion() + " is available"); Label lbChangeLog = new Label("Changelog:"); TextArea taChangeLog = new TextArea(newVersion.getChangeLog()); taChangeLog.setEditable(false);/*from w w w .jav a 2 s . c om*/ taChangeLog.setWrapText(true); Label lbSize = new Label("Size:"); Label lbSizeValue = new Label(FileUtils.byteCountToDisplaySize(newVersion.getSize())); Label lbPublished = new Label("Published"); Label lbPublishedValue = new Label( ZonedDateTime.parse(newVersion.getPublished()).format(DateTimeFormatter.RFC_1123_DATE_TIME)); final GridPane grid = new GridPane(); RowConstraints vAlign = new RowConstraints(); vAlign.setValignment(VPos.TOP); grid.getRowConstraints().add(vAlign); grid.setHgap(10); grid.setVgap(10); grid.add(lbChangeLog, 0, 0); grid.add(taChangeLog, 1, 0); grid.add(lbPublished, 0, 1); grid.add(lbPublishedValue, 1, 1); grid.add(lbSize, 0, 2); grid.add(lbSizeValue, 1, 2); this.getDialogPane().setContent(grid); }
From source file:com.opentangerine.clean.Summary.java
/** * Display summary based on current state. *///from w w w . j a v a 2s. co m public void finished() { Logger.info(Clean.class, String.format("Summary: Found %s element(s) [%s]", this.count, FileUtils.byteCountToDisplaySize(this.total))); }
From source file:net.arp7.HdfsPerfTest.WriteFile.java
private static void writeFiles(final Configuration conf, final FileIoStats stats) throws InterruptedException, IOException { final FileSystem fs = FileSystem.get(conf); final AtomicLong filesLeft = new AtomicLong(params.getNumFiles()); final long runId = abs(rand.nextLong()); final byte[] data = new byte[params.getIoSize()]; Arrays.fill(data, (byte) 65); // Start the writers. final ExecutorService executor = Executors.newFixedThreadPool((int) params.getNumThreads()); final CompletionService<Object> ecs = new ExecutorCompletionService<>(executor); LOG.info("NumFiles=" + params.getNumFiles() + ", FileSize=" + FileUtils.byteCountToDisplaySize(params.getFileSize()) + ", IoSize=" + FileUtils.byteCountToDisplaySize(params.getIoSize()) + ", BlockSize=" + FileUtils.byteCountToDisplaySize(params.getBlockSize()) + ", ReplicationFactor=" + params.getReplication() + ", isThrottled=" + (params.maxWriteBps() > 0)); LOG.info("Starting " + params.getNumThreads() + " writer thread" + (params.getNumThreads() > 1 ? "s" : "") + "."); final long startTime = System.nanoTime(); for (long t = 0; t < params.getNumThreads(); ++t) { final long threadIndex = t; Callable<Object> c = new Callable<Object>() { @Override//from ww w . j a v a 2 s . co m public Object call() throws Exception { long fileIndex = 0; while (filesLeft.addAndGet(-1) >= 0) { final String fileName = "WriteFile-" + runId + "-" + (threadIndex + 1) + "-" + (++fileIndex); writeOneFile(new Path(params.getOutputDir(), fileName), fs, data, stats); } return null; } }; ecs.submit(c); } // And wait for all writers to complete. for (long t = 0; t < params.getNumThreads(); ++t) { ecs.take(); } final long endTime = System.nanoTime(); stats.setElapsedTime(endTime - startTime); executor.shutdown(); }
From source file:functionaltests.policy.ram.TestRamPolicy.java
public String getHalfLocalRam() { long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()) .getTotalPhysicalMemorySize(); return FileUtils.byteCountToDisplaySize(memorySize / 2).replaceAll(" GB", ""); }
From source file:com.discursive.jccook.net.FTPExample.java
private void secondExample() throws SocketException, IOException { FTPClient client = new FTPClient(); client.connect("ftp.ibiblio.org"); client.login("anonymous", ""); String remoteDir = "/pub/mirrors/apache/jakarta/ecs/binaries"; FTPFile[] remoteFiles = client.listFiles(remoteDir); System.out.println("Files in " + remoteDir); for (int i = 0; i < remoteFiles.length; i++) { String name = remoteFiles[i].getName(); long length = remoteFiles[i].getSize(); String readableLength = FileUtils.byteCountToDisplaySize(length); System.out.println(name + ":\t\t" + readableLength); }/* w w w . ja va 2 s .c o m*/ client.disconnect(); }
From source file:com.tasktop.c2c.server.hudson.configuration.service.HudsonMetricCollector.java
private void setDisUsage(long totalByteSize, ProjectServiceStatus status) { status.setServiceState(ServiceState.RUNNING); status.getMetrics().put(ProjectServiceStatus.DISK_USAGE_METRICS_KEY, totalByteSize + ""); status.getMetrics().put(ProjectServiceStatus.DISK_USAGE_HR_METRICS_KEY, FileUtils.byteCountToDisplaySize(totalByteSize)); }
From source file:com.tasktop.c2c.server.configuration.service.DatabaseMetricCollector.java
@Override public void collect(ProjectServiceStatus status) { String databaseName = databaseNamingStrategy.getCurrentTenantDatabaseName(); if (uppercaseDatbaseName) { databaseName = databaseName.toUpperCase(); }/*from w w w .j a va 2 s . c om*/ String query = sqlSizeQuery.replace(DATABSE_NAME_VAR, databaseName); LOG.debug(String.format("Collecting database metrics with query: [%s]", query)); Connection c = null; ResultSet resultSet = null; try { c = dataSource.getConnection(); resultSet = c.createStatement().executeQuery(query); if (resultSet.next()) { int totalByteSize = resultSet.getInt(1); status.setServiceState(ServiceState.RUNNING); status.getMetrics().put(ProjectServiceStatus.DISK_USAGE_METRICS_KEY, totalByteSize + ""); status.getMetrics().put(ProjectServiceStatus.DISK_USAGE_HR_METRICS_KEY, FileUtils.byteCountToDisplaySize(totalByteSize)); } } catch (SQLException e) { e.printStackTrace(); status.setServiceState(ServiceState.UNAVAILABLE); } finally { JdbcUtils.closeResultSet(resultSet); if (c != null) { try { c.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:extendedMetadata.ExtendedMetaDataComposite.java
private void updateComposite(final IExtendedMetadata metadata) { UIJob updateCompositeGUI = new UIJob("Update with new metadata") { @Override//from w w w .j a v a 2s.c om public IStatus runInUIThread(IProgressMonitor monitor) { if (metadata.getScanCommand() != null) scanCommand.setText(metadata.getScanCommand()); if (metadata.getFullPath() != null) fullPath.setText(metadata.getFullPath()); if (metadata.getFileName() != null) fileName.setText(metadata.getFileName()); if (metadata.getLastModified() != null) lastMod.setText(dateformat.format(metadata.getLastModified())); if (metadata.getCreation() != null) creation.setText(dateformat.format(metadata.getCreation())); if (metadata.getFileSize() != 0) size.setText(FileUtils.byteCountToDisplaySize(metadata.getFileSize())); if (metadata.getFileOwner() != null) owner.setText(metadata.getFileOwner()); if (metadata.getCreator() != null) creator.setText(metadata.getCreator()); view.setMeta(metadata); return Status.OK_STATUS; } }; updateCompositeGUI.schedule(); }
From source file:com.qatickets.domain.TicketFileAttachment.java
public String getSizeReadable() { return FileUtils.byteCountToDisplaySize(size); }