List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:org.exoplatform.wcm.notification.plugin.FileActivityChildPlugin.java
private String getSize(Node node) { double size = getFileSize(node); try {//www .j a v a 2 s .c o m if (node.hasNode(org.exoplatform.ecm.webui.utils.Utils.JCR_CONTENT)) { return FileUtils.byteCountToDisplaySize((long) size); } } catch (Exception e) { return StringUtils.EMPTY; } return StringUtils.EMPTY; }
From source file:org.fim.command.DisplayIgnoredFilesCommand.java
@Override public Object execute(Context context) throws Exception { StateManager manager = new StateManager(context); int lastStateNumber = manager.getLastStateNumber(); if (lastStateNumber == -1) { Logger.error("No State found"); return null; }//from ww w .j a v a2 s . c o m Path statFile = manager.getStateFile(lastStateNumber); if (Files.exists(statFile)) { State state = manager.loadState(lastStateNumber); System.out.printf("Files or directories ignored in State #%d: %s (%d files - %s)%n", lastStateNumber, formatDate(state.getTimestamp()), state.getFileCount(), FileUtils.byteCountToDisplaySize(state.getFilesContentLength())); if (state.getComment().length() > 0) { System.out.printf("\tComment: %s%n", state.getComment()); } Set<String> ignoredFiles = state.getIgnoredFiles(); displayIgnore(ignoredFiles); Console.newLine(); return ignoredFiles; } return null; }
From source file:org.fim.internal.hash.FileHasherPerformanceTest.java
@Test public void hashFiles() throws IOException { long start = System.currentTimeMillis(); List<FileHash> allHash = new ArrayList(); for (int fileCount = 0; fileCount < TOTAL_FILE_CONT; fileCount++) { Path fileToHash = context.getRepositoryRootDir().resolve("file_" + fileCount); allHash.add(cut.hashFile(fileToHash, Files.size(fileToHash))); }/*from w ww. ja v a 2s . c o m*/ long duration = System.currentTimeMillis() - start; System.out.println("Took: " + DurationFormatUtils.formatDuration(duration, "HH:mm:ss")); System.out.println("Total bytes hash=" + FileUtils.byteCountToDisplaySize(cut.getTotalBytesHashed())); }
From source file:org.fim.internal.hash.FileHasherTest.java
private void displayFileHash(long fileSize, FileHash fileHash) { System.out.println("File " + FileUtils.byteCountToDisplaySize(fileSize)); System.out.println("\tsmallBlockHash=" + fileHash.getSmallBlockHash()); System.out.println("\tmediumBlockHash=" + fileHash.getMediumBlockHash()); System.out.println("\tfullHash=" + fileHash.getFullHash()); System.out.println(""); }
From source file:org.fim.internal.hash.HashProgress.java
public String hashLegend() { StringBuilder sb = new StringBuilder(); for (int progressIndex = hashProgress.size() - 1; progressIndex >= 0; progressIndex--) { Pair<Character, Integer> progressPair = hashProgress.get(progressIndex); char marker = progressPair.getLeft(); sb.append(marker);//from www . jav a 2 s. c o m int fileLength = progressPair.getRight(); if (fileLength == 0) { sb.append(" otherwise"); } else { sb.append(" > ").append(FileUtils.byteCountToDisplaySize(fileLength)); } sb.append(", "); } String legend = sb.toString(); legend = legend.substring(0, legend.length() - 2); return legend; }
From source file:org.fim.internal.StateGenerator.java
private void displayStatistics(long start, State state) { long duration = System.currentTimeMillis() - start; String totalFileContentLengthStr = FileUtils.byteCountToDisplaySize(state.getFilesContentLength()); String totalBytesHashedStr = FileUtils.byteCountToDisplaySize(overallTotalBytesHashed); String durationStr = DurationFormatUtils.formatDuration(duration, "HH:mm:ss"); long durationSeconds = duration / 1000; if (durationSeconds <= 0) { durationSeconds = 1;//w w w. ja v a 2 s.c o m } long globalThroughput = overallTotalBytesHashed / durationSeconds; String throughputStr = FileUtils.byteCountToDisplaySize(globalThroughput); if (context.getHashMode() == dontHash) { Logger.info(String.format("Scanned %d files (%s), during %s%n", state.getFileCount(), totalFileContentLengthStr, durationStr)); } else { Logger.info( String.format("Scanned %d files (%s), hashed %s (avg %s/s), during %s%n", state.getFileCount(), totalFileContentLengthStr, totalBytesHashedStr, throughputStr, durationStr)); } }
From source file:org.fim.model.DuplicateResult.java
public DuplicateResult displayDuplicates() { if (context.isVerbose()) { for (DuplicateSet duplicateSet : duplicateSets) { System.out.println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"); System.out.println("- Duplicate set #" + (duplicateSets.indexOf(duplicateSet) + 1)); List<FileState> duplicatedFiles = duplicateSet.getDuplicatedFiles(); for (FileState fileState : duplicatedFiles) { if (duplicatedFiles.indexOf(fileState) == 0) { System.out.printf(" %s duplicated %d times%n", fileState.getFileName(), duplicatedFiles.size() - 1); } else { System.out.printf(" %s - %s%n", FileUtils.byteCountToDisplaySize(fileState.getFileLength()), fileState.getFileName()); }/*from w w w.j a v a 2 s. c o m*/ } Console.newLine(); } } System.out.printf("%d duplicated files spread into %d duplicate sets, %s of wasted space%n", duplicatedFilesCount, duplicateSets.size(), FileUtils.byteCountToDisplaySize(wastedSpace)); return this; }
From source file:org.fim.model.LogEntry.java
public void displayEntryHeader(PrintStream out) { out.printf("- State #%d: %s (%d %s - %s - generated%s using hash mode %s)%n", getStateNumber(), formatDate(getTimestamp()), getFileCount(), plural("file", getFileCount()), FileUtils.byteCountToDisplaySize(getFilesContentLength()), commitDetails.getFromSubDirectory() != null ? " from " + commitDetails.getFromSubDirectory() : "", commitDetails.getHashModeUsedToGetTheStatus()); if (getComment().length() > 0) { out.printf("\tComment: %s%n", getComment()); }/*from ww w. j a va2 s. co m*/ }
From source file:org.fim.model.LogResult.java
public void displayEntries() { for (LogEntry logEntry : logEntries) { System.out.printf("State #%d: %s (%d files - %s)%n", logEntry.getStateNumber(), formatDate(logEntry.getTimestamp()), logEntry.getFileCount(), FileUtils.byteCountToDisplaySize(logEntry.getFilesContentLength())); if (logEntry.getComment().length() > 0) { System.out.printf("\tComment: %s%n", logEntry.getComment()); }/*from w w w . j av a 2s .c om*/ displayCounts(logEntry.getModificationCounts()); Console.newLine(); } }
From source file:org.flowerplatform.core.file.FilePropertiesController.java
@Override public void populateWithProperties(Node node, ServiceContext<NodeService> context) { Object file;//from w w w . j a v a 2 s. c o m try { file = getFileAccessController().getFile(getFilePathWithRepo(node)); } catch (Exception e) { throw new RuntimeException(e); } node.getProperties().put(CoreConstants.NAME, getFileAccessController().getName(file)); node.getProperties().put(CoreConstants.HAS_CHILDREN, getFileAccessController().hasChildren(file)); Path path = Paths.get(getFileAccessController().getAbsolutePath(file)); Map<String, Object> atributes = null; try { atributes = Files.readAttributes(path, "lastModifiedTime,lastAccessTime,creationTime,isDirectory"); } catch (IOException e) { throw new RuntimeException(e); } for (Map.Entry<String, Object> entry : atributes.entrySet()) { switch (entry.getKey()) { case CoreConstants.FILE_LAST_ACCESS_TIME: case CoreConstants.FILE_LAST_MODIFIED_TIME: case CoreConstants.FILE_CREATION_TIME: node.getProperties().put(entry.getKey().toString(), new Date(((FileTime) entry.getValue()).toMillis())); break; case CoreConstants.FILE_IS_DIRECTORY: node.getProperties().put(FILE_IS_DIRECTORY, entry.getValue()); break; } } long size; if ((boolean) node.getProperties().get(FILE_IS_DIRECTORY)) { size = getFolderSize(file); node.getProperties().put(ICONS, ResourcesPlugin.getInstance().getResourceUrl("images/core/folder.gif")); } else { size = getFileAccessController().length(file); node.getProperties().put(IS_OPENABLE_IN_NEW_EDITOR, true); node.getProperties().put(ICONS, ResourcesPlugin.getInstance().getResourceUrl("images/core/file.gif")); } node.getProperties().put(FILE_SIZE, FileUtils.byteCountToDisplaySize(size)); }