List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:org.stem.ProtocolTest.java
@Test @Ignore // TODO: it's ignored because it's ran endlessly public void testClusterWritePerformance() throws Exception { Logger.getLogger("io.netty").setLevel(Level.OFF); clusterManagerClient.computeMapping(); StemClient client = new StemClient(); client.start();/* ww w.j a va2s. co m*/ byte[] blob = TestUtils.generateRandomBlob(65536); byte[] key = DigestUtils.md5(blob); long start, duration; long i = 0; start = System.nanoTime(); while (true) { i++; client.put(key, blob); if (i % 1000 == 0) { duration = System.nanoTime() - start; long rps = i * 1000000000 / duration; System.out.println( String.format("%s req/s, %s/s", rps, FileUtils.byteCountToDisplaySize(rps * blob.length))); start = System.nanoTime(); i = 0; } } }
From source file:org.structr.core.entity.File.java
public String getFormattedSize() { return FileUtils.byteCountToDisplaySize(getSize()); }
From source file:org.structr.web.entity.File.java
static String getFormattedSize(final File thisFile) { return FileUtils.byteCountToDisplaySize(thisFile.getSize()); }
From source file:org.talend.components.webtest.TestJsonSerialize.java
@Test public void TestSerializationSizes() throws IOException { FullExampleProperties fep = new FullExampleProperties(null); fep.stringProp.setValue("stringProp"); fep.tableProp.colEnum.setValue(FullExampleProperties.TableProperties.ColEnum.FOO); fep.tableProp.colString.setValue("foooo"); String jsonioString = fep.toSerialized(); System.out.println("jsonio:" + FileUtils.byteCountToDisplaySize(jsonioString.getBytes().length)); FullExampleProperties fepCopy = Properties.Helper.fromSerializedPersistent(jsonioString, FullExampleProperties.class).object; assertNull(fepCopy.hiddenTextProp.getValue()); assertEquals("foooo", fep.tableProp.colString.getValue()); assertEquals("foooo", fepCopy.tableProp.colString.getValue()); }
From source file:org.trzcinka.intellitrac.view.toolwindow.tickets.ticket_editor.AttachmentsListCellRenderer.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (!(value instanceof Attachment)) { throw new IllegalArgumentException( "AttachmentsListCellRenderer may render only Attachments, not " + value.getClass().getName()); }/*from ww w .jav a 2 s.com*/ Attachment attachment = (Attachment) value; final JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); ListCellRendererUtils.applyDefaultDisplaySettings(list, index, isSelected, cellHasFocus, panel); JLabel fileName = new JLabel(attachment.getFileName()); fileName.setForeground(panel.getForeground()); panel.add(fileName); String additionalTextString = MessageFormat.format( BundleLocator.getBundle() .getString("tool_window.tickets.ticket_editor.attachments.attachment_info"), FileUtils.byteCountToDisplaySize(attachment.getSize()), attachment.getAuthor()); JLabel additionalText = new JLabel(additionalTextString); additionalText.setForeground(panel.getForeground()); panel.add(additionalText); return panel; }
From source file:org.whitesource.agent.hash.HashCalculator.java
/** * Calculates 3 hashes for the given file: * * 1. Hash of the file without new lines and whitespaces * 2. Hash of the most significant bits of the file without new lines and whitespaces * 3. Hash of the least significant bits of the file without new lines and whitespaces * // w ww . jav a 2 s. co m * @param file input * @return HashCalculationResult with all three hashes * @throws IOException exception1 */ public HashCalculationResult calculateSuperHash(File file) throws IOException { // Ignore files smaller than 0.5kb long fileSize = file.length(); if (fileSize <= FILE_MIN_SIZE_THRESHOLD) { logger.debug("Ignored file " + file.getName() + " (" + FileUtils.byteCountToDisplaySize(fileSize) + "): minimum file size is 512B"); return null; } if (fileSize >= FILE_MAX_SIZE_THRESHOLD) { logger.debug("Ignore file {}, ({}): maximum file size is 2GB", file.getName(), FileUtils.byteCountToDisplaySize(fileSize)); return null; } HashCalculationResult result = null; try { result = calculateSuperHash(FileUtils.readFileToByteArray(file)); } catch (OutOfMemoryError e) { logger.debug(MessageFormat.format("Failed calculating SHA-1 for file {0}: size too big {1}", file.getAbsolutePath(), FileUtils.byteCountToDisplaySize(fileSize))); } return result; }
From source file:org.whitesource.agent.hash.HashCalculator.java
/** * Calculates 3 hashes for the given bytes: * * 1. Hash of the file without new lines and whitespaces * 2. Hash of the most significant bits of the file without new lines and whitespaces * 3. Hash of the least significant bits of the file without new lines and whitespaces * * @param bytes to calculate/*from w ww. jav a 2s.com*/ * @return HashCalculationResult with all three hashes * @throws IOException exception2 */ public HashCalculationResult calculateSuperHash(byte[] bytes) throws IOException { HashCalculationResult result = null; // Remove white spaces byte[] bytesWithoutSpaces = stripWhiteSpaces(bytes); long fileSize = bytesWithoutSpaces.length; if (fileSize < FILE_MIN_SIZE_THRESHOLD) { // Ignore files smaller 1/2 kb logger.debug("Ignoring file with size " + FileUtils.byteCountToDisplaySize(fileSize) + ": minimum file size is 512B"); } else if (fileSize <= FILE_PARTIAL_HASH_MIN_SIZE) { // Don't calculate msb and lsb hashes for files smaller than 2kb String fullFileHash = calculateByteArrayHash(bytesWithoutSpaces, HashAlgorithm.SHA1); result = new HashCalculationResult(fullFileHash); } else if (fileSize <= FILE_SMALL_SIZE) { // Handle 2kb->3kb files result = hashBuckets(bytesWithoutSpaces, FILE_SMALL_BUCKET_SIZE); } else { int baseLowNumber = 1; int digits = (int) Math.log10(fileSize); int i = 0; while (i < digits) { baseLowNumber = baseLowNumber * 10; i++; } double highNumber = Math.ceil((fileSize + 1) / (float) baseLowNumber) * baseLowNumber; double lowNumber = highNumber - baseLowNumber; double bucketSize = (highNumber + lowNumber) / 4; result = hashBuckets(bytesWithoutSpaces, bucketSize); } return result; }
From source file:org.whitesource.agent.hash.HashCalculator.java
/** * Removes all JavaScript comments from the file and calculates SHA-1 checksum. * * @param file to calculate// w w w . ja va 2 s.c om * @return Calculated SHA-1 checksums for the given file. */ public Map<ChecksumType, String> calculateJavaScriptHashes(File file) throws WssHashException { Map<ChecksumType, String> checksums = new EnumMap<>(ChecksumType.class); try { long fileLength = file.length(); if (fileLength >= FILE_MAX_SIZE_THRESHOLD) { logger.debug("Ignore file {}, ({}): maximum file size is 2GB", file.getName(), FileUtils.byteCountToDisplaySize(fileLength)); return checksums; } checksums = calculateJavaScriptHashes(FileUtils.readFileToByteArray(file)); } catch (Exception e) { throw new WssHashException("Error calculating JavaScript hash: " + e.getMessage()); } return checksums; }
From source file:org.whitesource.docker.ExtractProgressIndicator.java
@Override public void run() { long currentSize; do {/*ww w . j a va 2 s .c o m*/ currentSize = file.length(); StringBuilder sb = new StringBuilder(LOG_PREFIX); int actualAnimationIndex = animationIndex % (ANIMATION_FRAMES); sb.append(progressAnimation.get((actualAnimationIndex) % ANIMATION_FRAMES)); animationIndex++; // draw progress bar sb.append(PROGRESS_BAR_PREFIX); double percentage = ((double) currentSize / targetSize) * 100; int progressionBlocks = (int) (percentage / 3); for (int i = 0; i < progressionBlocks; i++) { sb.append(PROGRESS_FILL); } for (int i = progressionBlocks; i < 33; i++) { sb.append(EMPTY_STRING); } sb.append(PROGRESS_BAR_SUFFIX); System.out.print(MessageFormat.format(sb.toString(), (int) percentage, FileUtils.byteCountToDisplaySize(currentSize))); try { Thread.sleep(REFRESH_RATE); } catch (InterruptedException e) { // ignore } // check if finished, sometimes actual size might be larger than target size if (finished) { break; } } while (currentSize < targetSize); // clear progress animation System.out.print(CLEAR_PROGRESS); }
From source file:org.xlcloud.console.images.controllers.ImageBean.java
public String getImageSize() { return FileUtils.byteCountToDisplaySize(image.getSize()); }