@Override public long length(URI fileUri) throws IOException { File file = new File(decodeURI(fileUri.getRawPath())); if (file.isDirectory()) { throw new IllegalArgumentException("File is directory"); } return FileUtils.sizeOf(file); }
@Test public void testCompareSizeOf() { final File start = new File("src/test/java"); final long sizeLong1 = FileUtils.sizeOf(start); final BigInteger sizeBig = FileUtils.sizeOfAsBigInteger(start); final long sizeLong2 = FileUtils.sizeOf(start); assertEquals("Size should not change", sizeLong1, sizeLong2); assertEquals("longSize should equal BigSize", sizeLong1, sizeBig.longValue()); }
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); } }
long sizeInBytes = FileUtils.sizeOf(dir); LOG.info("Cleaning up: Removing {}, {} KB", path, sizeInBytes * 1e-3);
/** * Constuctor. * * @param stormConf configuration map for Storm cluster * @param workerLogs {@link WorkerLogs} instance * @param directoryCleaner {@link DirectoryCleaner} instance * @param logRootDir root log directory * @param metricsRegistry The logviewer metrics registry */ public LogCleaner(Map<String, Object> stormConf, WorkerLogs workerLogs, DirectoryCleaner directoryCleaner, File logRootDir, StormMetricsRegistry metricsRegistry) { this.stormConf = stormConf; this.intervalSecs = ObjectReader.getInt(stormConf.get(LOGVIEWER_CLEANUP_INTERVAL_SECS), null); this.logRootDir = logRootDir; this.workerLogs = workerLogs; this.directoryCleaner = directoryCleaner; maxSumWorkerLogsSizeMb = ObjectReader.getInt(stormConf.get(LOGVIEWER_MAX_SUM_WORKER_LOGS_SIZE_MB)); maxPerWorkerLogsSizeMb = ObjectReader.getInt(stormConf.get(LOGVIEWER_MAX_PER_WORKER_LOGS_SIZE_MB)); maxPerWorkerLogsSizeMb = Math.min(maxPerWorkerLogsSizeMb, (long) (maxSumWorkerLogsSizeMb * 0.5)); LOG.info("configured max total size of worker logs: {} MB, max total size of worker logs per directory: {} MB", maxSumWorkerLogsSizeMb, maxPerWorkerLogsSizeMb); //Switch to CachedGauge if this starts to hurt performance metricsRegistry.registerGauge("logviewer:worker-log-dir-size", () -> FileUtils.sizeOf(logRootDir)); this.cleanupRoutineDuration = metricsRegistry.registerTimer("logviewer:cleanup-routine-duration-ms"); this.numFilesCleanedUp = metricsRegistry.registerHistogram("logviewer:num-files-cleaned-up"); this.diskSpaceFreed = metricsRegistry.registerHistogram("logviewer:disk-space-freed-in-bytes"); this.numFileRemovalExceptions = metricsRegistry.registerMeter(ExceptionMeterNames.NUM_FILE_REMOVAL_EXCEPTIONS); this.numCleanupExceptions = metricsRegistry.registerMeter(ExceptionMeterNames.NUM_CLEANUP_EXCEPTIONS); }
@Test public void testSizeOf() throws Exception { final File file = new File(getTestDirectory(), getName()); // Null argument try { FileUtils.sizeOf(null); fail("Exception expected."); } catch (final NullPointerException ignore) { } // Non-existent file try { FileUtils.sizeOf(file); fail("Exception expected."); } catch (final IllegalArgumentException ignore) { } // Creates file file.createNewFile(); file.deleteOnExit(); // New file assertEquals(0, FileUtils.sizeOf(file)); file.delete(); // Existing file assertEquals("Unexpected files size", testFile1Size, FileUtils.sizeOf(testFile1)); // Existing directory assertEquals("Unexpected directory size", TEST_DIRECTORY_SIZE, FileUtils.sizeOf(getTestDirectory())); }
long size = FileUtils.sizeOf( file );
private boolean commonCheckThatLogFileAssertionSucceeds(AssertionInfo info, File actual, Object[] sequence) { checkIsNotNull(sequence); assertNotNull(info, actual); files.assertIsFile(info, actual); files.assertExists(info, actual); // if both actual and values are empty, then assertion passes. if (FileUtils.sizeOf(actual) == 0 && sequence.length == 0) { return true; } failIfEmptySinceActualIsNotEmpty(sequence); return false; }
@Test public void testJavadocParseError() throws Exception { try { JavadocPropertiesGenerator.main( getPath("InputJavadocPropertiesGeneratorJavadocParseError.java"), "--destfile", DESTFILE.getAbsolutePath()); fail("Exception was expected"); } catch (IllegalArgumentException ex) { assertTrue("Invalid error message", ex.getMessage().contains( "mismatched input '<EOF>' expecting JAVADOC_INLINE_TAG_END")); } assertEquals("File '" + DESTFILE + "' must be empty", 0, FileUtils.sizeOf(DESTFILE)); }
@Test public void testNotImplementedTag() throws Exception { try { JavadocPropertiesGenerator.main( getPath("InputJavadocPropertiesGeneratorNotImplementedTag.java"), "--destfile", DESTFILE.getAbsolutePath()); fail("Exception was expected"); } catch (CheckstyleException ex) { assertEquals("Invalid error message", "Unsupported inline tag LINK_LITERAL", ex.getMessage()); } assertEquals("File '" + DESTFILE + "' must be empty", 0, FileUtils.sizeOf(DESTFILE)); }
@Test public void testNotConstants() throws Exception { JavadocPropertiesGenerator.main(getPath("InputJavadocPropertiesGeneratorNotConstants.java"), "--destfile", DESTFILE.getAbsolutePath()); assertEquals("Unexpected error log", "", systemErr.getLog()); assertEquals("Unexpected output log", "", systemOut.getLog()); assertEquals("File '" + DESTFILE + "' must be empty", 0, FileUtils.sizeOf(DESTFILE)); }
@Test public void testEmptyJavadoc() throws Exception { JavadocPropertiesGenerator.main(getPath("InputJavadocPropertiesGeneratorEmptyJavadoc.java"), "--destfile", DESTFILE.getAbsolutePath()); assertEquals("Unexpected error log", "", systemErr.getLog()); assertEquals("Unexpected output log", "", systemOut.getLog()); assertEquals("File '" + DESTFILE + "' must be empty", 0, FileUtils.sizeOf(DESTFILE)); }
while ((nRead = result.getEntity().getContent().read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); long fileSize = FileUtils.sizeOf(localFile); if (fileSize > nextLog) { System.err.print("\r" + ansi().eraseLine());
ourLog.info("Successfully Loaded example pack ({})", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(inputFile))); IOUtils.closeQuietly(result.getEntity().getContent());
if (!theFile.exists()) { actuallyWrite = true; } else if (FileUtils.sizeOf(theFile) != bytesToWrite.length) { actuallyWrite = true; } else {
/** * Return the total size of the local pool directory. * * @return size in bytes */ public long getTotalSize() { return (this.baseDir.exists()) ? FileUtils.sizeOf(this.baseDir) : 0; }
List<File> uncompressTarGzFile(File inputFile, File outputDir, Consumer<ProgressEntity> stateCallback) { try (CountingInputStream countingInputStream = new CountingInputStream(new FileInputStream(inputFile)); InputStream inputStream = new GZIPInputStream(countingInputStream)) { final long finalSize = FileUtils.sizeOf(inputFile); return uncompress(inputStream, countingInputStream, outputDir, finalSize, stateCallback); } catch (IOException e) { throw new ArchiveException(TAR_ERROR_MESSAGE, e); } }
List<File> uncompressTarFile(File inputFile, File outputDir, Consumer<ProgressEntity> stateCallback) { try (CountingInputStream countingInputStream = new CountingInputStream(new FileInputStream(inputFile))) { final long finalSize = FileUtils.sizeOf(inputFile); return uncompress(countingInputStream, countingInputStream, outputDir, finalSize, stateCallback); } catch (IOException e) { throw new ArchiveException(TAR_ERROR_MESSAGE, e); } }
List<File> uncompressZipFile(File inputFile, File outputDir, Consumer<ProgressEntity> stateCallback) { try (CountingInputStream inputStream = new CountingInputStream(new FileInputStream(inputFile))) { final long finalSize = FileUtils.sizeOf(inputFile); List<File> files = uncompress(inputStream, inputStream, outputDir, finalSize, stateCallback); return files; } catch (IOException e) { throw new ArchiveException(ZIP_ERROR_MESSAGE, e); } }
/** * Create a dense matrix based on the data in a particular file. * @param path Path to the matrix data file. * @throws java.io.IOException */ public DenseMatrix(File path) throws IOException { this.path = path; info("initializing sparse matrix with file length " + FileUtils.sizeOf(path)); this.channel = (new FileInputStream(path)).getChannel(); readHeaders(); rowBuffers = new MemoryMappedMatrix(path, channel, rowIds, rowOffsets); }