List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:br.com.ingenieux.mojo.aws.util.BeanstalkerS3Client.java
public String asNumber(long bytesTransfered) { // Extra Pedantry: I love *-ibytes return FileUtils.byteCountToDisplaySize(bytesTransfered).replaceAll("B$", "iB"); }
From source file:com.talis.entity.db.EntityDatabasePerfTestBase.java
@Test public void benchmarkAccessSingleGraph() throws EntityDatabaseException { System.out.println("Accessing Single Graph"); int graphs = 100000; int stmtsPerGraph = 20; long start = System.currentTimeMillis(); db.begin();//from w w w . jav a 2 s .co m for (int i = 0; i < graphs; i++) { Node thisGraph = Node.createURI(graph.getURI() + "_" + i); db.put(subject, thisGraph, getQuads(thisGraph, subject, stmtsPerGraph)); } db.commit(); System.out.println(String.format("Populated %s graphs (%s total statements) in %s ms", graphs, graphs * stmtsPerGraph, (System.currentTimeMillis() - start))); int iter = Math.round(graphs / 4); Random r = new Random(); start = System.currentTimeMillis(); for (int i = 0; i < iter; i++) { Node thisGraph = Node.createURI(graph.getURI() + "_" + r.nextInt(graphs)); db.getGraph(thisGraph); } long end = System.currentTimeMillis(); long duration = end - start; System.out.println(String.format("Iterations: %s, Total: %s, PerOp: %s", iter, duration, (double) ((double) duration / (double) iter))); long size = FileUtils.sizeOfDirectory(tmpDir.getRoot()); System.out.println(String.format("Size on disk : %s (%s)", FileUtils.byteCountToDisplaySize(size), size)); }
From source file:ddf.catalog.resource.download.ResourceRetrievalMonitor.java
@Override public void run() { long bytesRead = reliableResourceCallable.getBytesRead(); long chunkByteCount = bytesRead - previousBytesRead; if (chunkByteCount > 0) { long transferSpeed = (chunkByteCount / monitorPeriod) * 1000; // in bytes per second LOGGER.debug("Downloaded {} bytes in last {} ms. Total bytes read = {}, transfer speed = {}/second", chunkByteCount, monitorPeriod, bytesRead, FileUtils.byteCountToDisplaySize(transferSpeed)); previousBytesRead = reliableResourceCallable.getBytesRead(); if (null != eventPublisher) { eventPublisher.postRetrievalStatus(resourceResponse, DownloadsStatusEventPublisher.ProductRetrievalStatus.IN_PROGRESS, metacard, null, bytesRead, downloadIdentifier); } else {//from w w w . j a v a 2 s.c om LOGGER.debug("Event publisher is null "); } } else { LOGGER.debug( "No bytes downloaded in last {} ms - cancelling ResourceRetrievalMonitor and ReliableResourceCallable future (thread).", monitorPeriod); // Stop this ResourceRetrievalMonitor since the ReliableResourceCallable being watched will be stopped now cancel(); // Stop the download thread // synchronized so that Callable can finish any writing to OutputStreams before being canceled synchronized (reliableResourceCallable) { LOGGER.debug("Setting interruptCaching on ReliableResourceCallable thread"); reliableResourceCallable.setInterruptDownload(true); // Without this the Future that is running the ReliableResourceCallable will not stop boolean status = future.cancel(true); LOGGER.debug("future cancelling status = {}", status); } } }
From source file:it.anyplace.sync.core.beans.FileInfo.java
public String describeSize() { return isFile() ? FileUtils.byteCountToDisplaySize(getSize()) : ""; }
From source file:fr.duminy.jbackup.core.archive.Compressor.java
public void compress(ArchiveParameters archiveParameters, List<SourceWithPath> files, final TaskListener listener, Cancellable cancellable) throws ArchiveException { final String name = archiveParameters.getArchive().toString(); final MutableLong processedSize = new MutableLong(); try (OutputStream fos = Files.newOutputStream(archiveParameters.getArchive()); ArchiveOutputStream output = factory.create(fos)) { LOG.info("Backup '{}': creating archive {}", name, archiveParameters.getArchive()); for (final SourceWithPath file : files) { if ((cancellable != null) && cancellable.isCancelled()) { break; }//from w w w .ja v a2 s. com LOG.info("Backup '{}': compressing file {}", name, file.getPath().toAbsolutePath()); try (InputStream input = createCountingInputStream(listener, processedSize, Files.newInputStream(file.getPath()))) { final String path; if (archiveParameters.isRelativeEntries()) { Path source = file.getSource(); if (Files.isDirectory(source)) { if (source.getParent() == null) { path = source.relativize(file.getPath()).toString(); } else { path = source.getParent().relativize(file.getPath()).toString(); } } else { path = file.getPath().getFileName().toString(); } } else { path = file.getPath().toString(); } LOG.info("Backup '{}': adding entry {}", new Object[] { name, path }); output.addEntry(path, input); } } LOG.info("Backup '{}': archive {} created ({})", new Object[] { name, archiveParameters.getArchive(), FileUtils.byteCountToDisplaySize(Files.size(archiveParameters.getArchive())) }); } catch (IOException e) { throw new ArchiveException(e); } catch (Exception e) { throw new ArchiveException(e); } }
From source file:eionet.webq.dto.FileInfo.java
/** * Get user friendly formatted file size. * * @return file size as String//from ww w .j a v a 2 s. c o m */ @XmlElement(name = "fileSize") public String getSize() { return FileUtils.byteCountToDisplaySize(sizeInBytes); }
From source file:io.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page.// ww w . j a v a2s .c o m */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); TemplateEngines.getDefault().render(TemplateContext.builder().request(req).response(resp) .template(TOOLS_TEMPLATE).locale(req.getLocale()) .contextObject(ContextObject.newContextObject().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()).put("totalBundles", bundles.length) .put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:au.edu.anu.portal.portlets.rss.FeedParser.java
/** * Helper to format the length from bytes into a human readable format eg 126 kB * @param length//from w ww .ja v a 2 s .c o m * @return */ private static String formatLength(long length) { return FileUtils.byteCountToDisplaySize(length); }
From source file:com.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page.//w w w. j a v a 2s .co m */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); TemplateEngine.getInstance() .render(TemplateContext.builder().request(req).response(resp).template(TOOLS_TEMPLATE) .locale(req.getLocale()) .templateData(TemplateData.newTemplateData().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()) .put("totalBundles", bundles.length).put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:eu.over9000.skadi.service.DownloadService.java
@Override protected Task<File> createTask() { return new Task<File>() { protected File call() throws Exception { LOGGER.info(String.format("Downloading file %s to %s", DownloadService.this.remoteUrl, DownloadService.this.localFile.getAbsolutePath())); HttpGet httpGet = new HttpGet(DownloadService.this.remoteUrl); HttpResponse response = DownloadService.this.httpClient.execute(httpGet); OutputStream localFileStream = null; try (InputStream remoteContentStream = response.getEntity().getContent()) { long fileSize = response.getEntity().getContentLength(); LOGGER.debug(String.format("Size of file to download is %s", fileSize)); localFileStream = new FileOutputStream(DownloadService.this.localFile); byte[] buffer = new byte[BUFFER_SIZE]; int sizeOfChunk; int amountComplete = 0; long startTime = System.nanoTime(); while ((sizeOfChunk = remoteContentStream.read(buffer)) != -1) { if (this.isCancelled()) { this.updateMessage("Download cancelled"); return null; }//from w ww . ja v a 2 s . c om localFileStream.write(buffer, 0, sizeOfChunk); amountComplete += sizeOfChunk; this.updateProgress(amountComplete, fileSize); long bytesec = (long) ((double) amountComplete / (System.nanoTime() - startTime) * NANOS_IN_SECOND); this.updateMessage(String.format("Downloaded %s of %s kB (%d%% @%s/s)", FileUtils.byteCountToDisplaySize(amountComplete), FileUtils.byteCountToDisplaySize(fileSize), (int) ((double) amountComplete / (double) fileSize * 100.0), FileUtils.byteCountToDisplaySize(bytesec))); } this.updateMessage("Download completed"); return DownloadService.this.localFile; } finally { if (localFileStream != null) { localFileStream.close(); } } } }; }