List of usage examples for org.apache.commons.io FileUtils ONE_KB
long ONE_KB
To view the source code for org.apache.commons.io FileUtils ONE_KB.
Click Source Link
From source file:edu.kit.dama.transfer.client.util.TestDataBuilder.java
/** * The entry point./*from ww w. j a v a 2 s .co m*/ * * @param args Command line args. */ public static void main(String[] args) { try { FileUtils.forceMkdir(new File(targetDir)); byte[] oneMegaByte = buildRandomData((int) FileUtils.ONE_KB); for (int i = 0; i < BASE_FILES; i++) { File f = new File(targetDir + i + ".bin"); LOGGER.debug(" - Writing file {}", f); FileUtils.writeByteArrayToFile(f, oneMegaByte); } for (int j = 0; j < SUB_DIRS; j++) { String subdir = targetDir + "subDir" + j; for (int k = 0; k < SUB_SUB_DIRS; k++) { String subsubdir = subdir + "/subsubdir" + k; oneMegaByte = buildRandomData((int) FileUtils.ONE_KB); for (int i = 0; i < FILES_IN_SUB_SUB_DIRS; i++) { File f = new File(subsubdir + File.separator + i + "-" + j + "-" + k + ".bin"); LOGGER.debug(" - Writing file {}", f); FileUtils.writeByteArrayToFile(f, oneMegaByte); } } } } catch (IOException ioe) { LOGGER.error("Failed to build data", ioe); } }
From source file:com.joyent.manta.benchmark.Benchmark.java
/** * Entrance to benchmark utility.//from ww w . ja v a 2s . co m * @param argv param1: method, param2: size of object in kb, param3: no of iterations, param4: threads * @throws Exception when something goes wrong */ public static void main(final String[] argv) throws Exception { config = new ChainedConfigContext(new DefaultsConfigContext(), new SystemSettingsConfigContext()); client = new MantaClient(config); testDirectory = String.format("%s/stor/java-manta-integration-tests/benchmark-%s", config.getMantaHomeDirectory(), testRunId); if (argv.length == 0) { System.err.println("Benchmark requires the following parameters:\n" + "method, size of object in kb, number of iterations, concurrency"); } String method = argv[0]; try { if (argv.length > 1) { sizeInBytesOrNoOfDirs = Integer.parseInt(argv[1]); } else { sizeInBytesOrNoOfDirs = DEFAULT_OBJ_SIZE_KB; } final int iterations; if (argv.length > 2) { iterations = Integer.parseInt(argv[2]); } else { iterations = DEFAULT_ITERATIONS; } final int concurrency; if (argv.length > 3) { concurrency = Integer.parseInt(argv[3]); } else { concurrency = DEFAULT_CONCURRENCY; } final long actualIterations = perThreadCount(iterations, concurrency) * concurrency; System.out.printf( "Testing latencies on a %d kb object for %d " + "iterations with a concurrency value of %d\n", sizeInBytesOrNoOfDirs, actualIterations, concurrency); setupTestDirectory(); String path = addTestFile(FileUtils.ONE_KB * sizeInBytesOrNoOfDirs); if (concurrency == 1) { singleThreadedBenchmark(method, path, iterations); } else { multithreadedBenchmark(method, path, iterations, concurrency); } } catch (IOException e) { LOG.error("Error running benchmark", e); } finally { cleanUp(); client.closeWithWarning(); } }
From source file:kaljurand_at_gmail_dot_com.diktofon.MyFileUtils.java
public static String getSizeAsString(long size) { String sizeAsString;/* w ww .jav a2 s.com*/ if (size > FileUtils.ONE_MB) { sizeAsString = (long) (size / FileUtils.ONE_MB) + "MB"; } else if (size > FileUtils.ONE_KB) { sizeAsString = (long) (size / FileUtils.ONE_KB) + "kB"; } else { sizeAsString = size + "b"; } if (size > NetSpeechApiUtils.MAX_AUDIO_FILE_LENGTH) { sizeAsString += " !!!"; } return sizeAsString; }
From source file:net.pickapack.util.StorageUnitHelper.java
/** * Convert the specified display size to the byte count. * * @param displaySize the display size//w ww . ja va2 s . c o m * @return the byte count corresponding to the specified display size */ public static long displaySizeToByteCount(String displaySize) { String[] parts = displaySize.split(" "); if (parts.length == 2) { double scale = Double.parseDouble(parts[0]); String unit = parts[1]; if (unit.equals("KB")) { return (long) (scale * FileUtils.ONE_KB); } else if (unit.equals("MB")) { return (long) (scale * FileUtils.ONE_MB); } else if (unit.equals("GB")) { return (long) (scale * FileUtils.ONE_GB); } else if (unit.equals("TB")) { return (long) (scale * FileUtils.ONE_TB); } else if (unit.equals("PB")) { return (long) (scale * FileUtils.ONE_PB); } else if (unit.equals("EB")) { return (long) (scale * FileUtils.ONE_EB); } } throw new IllegalArgumentException(); }
From source file:kaljurand_at_gmail_dot_com.diktofon.MyFileUtils.java
public static String getSizeAsStringExact(long size) { String sizeAsString;/*from www . ja va2 s. co m*/ if (size > FileUtils.ONE_MB) { sizeAsString = String.format("%.1fMB", (float) size / FileUtils.ONE_MB); } else if (size > FileUtils.ONE_KB) { sizeAsString = String.format("%.1fkB", (float) size / FileUtils.ONE_KB); } else { sizeAsString = size + "b"; } if (size > NetSpeechApiUtils.MAX_AUDIO_FILE_LENGTH) { sizeAsString += " !!!"; } return sizeAsString; }
From source file:com.docd.purefm.commandline.CommandDu.java
public static long du_s(@NonNull final GenericFile file) { final List<String> result = CommandLine.executeForResult(new CommandDu(file)); if (result == null || result.isEmpty()) { return 0L; }/*from w w w . j av a 2s. c o m*/ final String res = result.get(0); final int resLength = res.length(); final StringBuilder lengthString = new StringBuilder(resLength); for (int i = 0; i < resLength; i++) { final char character = res.charAt(i); if (Character.isDigit(character)) { lengthString.append(character); } else { break; } } try { return Long.parseLong(lengthString.toString()) * FileUtils.ONE_KB; } catch (NumberFormatException e) { return 0L; } }
From source file:net.sf.logsaw.core.internal.logresource.simple.ProgressingInputStream.java
@Override public int read(byte[] b, int off, int len) throws IOException { int read = super.read(b, off, len); processed += read;/*from w w w .ja v a 2 s. c o m*/ while (processed > FileUtils.ONE_KB) { // Advance progress monitor processed -= FileUtils.ONE_KB; monitor.worked(1); } return read; }
From source file:ee.ioc.phon.android.speak.Utils.java
/** * <p>Pretty-prints an integer value which expresses a size * of some data.</p>/*from ww w .j a v a2s . c o m*/ */ public static String getSizeAsString(int size) { if (size > FileUtils.ONE_MB) { return String.format("%.1fMB", (float) size / FileUtils.ONE_MB); } if (size > FileUtils.ONE_KB) { return String.format("%.1fkB", (float) size / FileUtils.ONE_KB); } return size + "b"; }
From source file:fr.paris.lutece.plugins.plu.utils.PluUtils.java
/** * Transform a byte size to a readable size including units * @param size size in bytes/* w w w .java 2 s. c o m*/ * @return size in string */ public static String formatSize(Long size) { String displaySize; if (size / FileUtils.ONE_GB > 0) { displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_GO, BigDecimal.ROUND_CEILING)) + " GO"; } else if (size / FileUtils.ONE_MB > 0) { displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_MO, BigDecimal.ROUND_CEILING)) + " MO"; } else if (size / FileUtils.ONE_KB > 0) { displaySize = String.valueOf(new BigDecimal(size).divide(BD_ONE_KO, BigDecimal.ROUND_CEILING)) + " KO"; } else { displaySize = String.valueOf(size) + " octets"; } return displaySize; }
From source file:com.uber.hoodie.func.TestBoundedInMemoryQueue.java
@SuppressWarnings("unchecked") @Test(timeout = 60000)/* w ww . j av a 2 s.co m*/ public void testRecordReading() throws Exception { final int numRecords = 128; final List<HoodieRecord> hoodieRecords = hoodieTestDataGenerator.generateInserts(commitTime, numRecords); final BoundedInMemoryQueue<HoodieRecord, Tuple2<HoodieRecord, Optional<IndexedRecord>>> queue = new BoundedInMemoryQueue( FileUtils.ONE_KB, getTransformFunction(HoodieTestDataGenerator.avroSchema)); // Produce Future<Boolean> resFuture = executorService.submit(() -> { new IteratorBasedQueueProducer<>(hoodieRecords.iterator()).produce(queue); queue.close(); return true; }); final Iterator<HoodieRecord> originalRecordIterator = hoodieRecords.iterator(); int recordsRead = 0; while (queue.iterator().hasNext()) { final HoodieRecord originalRecord = originalRecordIterator.next(); final Optional<IndexedRecord> originalInsertValue = originalRecord.getData() .getInsertValue(HoodieTestDataGenerator.avroSchema); final Tuple2<HoodieRecord, Optional<IndexedRecord>> payload = queue.iterator().next(); // Ensure that record ordering is guaranteed. Assert.assertEquals(originalRecord, payload._1()); // cached insert value matches the expected insert value. Assert.assertEquals(originalInsertValue, payload._1().getData().getInsertValue(HoodieTestDataGenerator.avroSchema)); recordsRead++; } Assert.assertFalse(queue.iterator().hasNext() || originalRecordIterator.hasNext()); // all the records should be read successfully. Assert.assertEquals(numRecords, recordsRead); // should not throw any exceptions. resFuture.get(); }