List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:net.malisis.advert.gui.manager.AdvertList.java
@Override public void drawElementForeground(GuiRenderer renderer, int mouseX, int mouseY, float partialTick, ClientAdvert advert, boolean isHovered) { //Name/*from w w w . j a v a 2 s .c om*/ int x = 2; fro.color = isHovered ? 0xFFFF99 : 0xFFFFFF; fro.shadow = true; fro.fontScale = 1; fro.saveDefault(); renderer.drawText(font, advert.getName(), x, 2, 0, fro); x += font.getStringWidth(advert.getName(), fro) + 6; //Image Dimensions x = Math.max(70, x); fro.color = isHovered ? 0x666666 : 0x444444; fro.shadow = false; fro.fontScale = 2F / 3F; fro.saveDefault(); String dim = advert.getWidth() + "x" + advert.getHeight(); renderer.drawText(font, dim, x, 5, 0, fro); x += font.getStringWidth(dim, fro) + 3; //File size String size = FileUtils.byteCountToDisplaySize(advert.getSize()); renderer.drawText(font, "(" + size + ")", x, 5, 0, fro); //URL String url = font.clipString(advert.getUrl(), getWidth() - 6, fro, true); renderer.drawText(font, url, 2, 13, 0, fro); }
From source file:com.adobe.acs.commons.util.impl.AbstractCacheMBean.java
@Override public final String getCacheSize() { // Iterate through the cache entries and compute the total size of byte array. long size = 0L; final Map<K, V> map = getCacheAsMap(); for (final Map.Entry<K, V> entry : map.entrySet()) { size += getBytesLength(entry.getValue()); }//from ww w .java 2s. co m // Convert bytes to human-friendly format return FileUtils.byteCountToDisplaySize(size); }
From source file:de.mpg.imeji.logic.vo.Item.java
/** * * @return human readable file size */ public String getFileSizeHumanReadable() { return FileUtils.byteCountToDisplaySize(fileSize); }
From source file:com.willkara.zeteo.filetypes.impl.BaseFileType.java
/** * Returns the size of a file into a human readable string. * * @param size The size of the file (long) * @return A String containing a human readable value of the size. *//*from w ww .j a v a 2s .c o m*/ @Override public String getFormattedFileSize(long size) { return FileUtils.byteCountToDisplaySize(size); }
From source file:fr.inria.atlanmod.neo4emf.neo4jresolver.runtimes.internal.Neo4jZippedInstaller.java
public String getDescriptionText() { StringBuilder builder = new StringBuilder(); builder.append(description);//from w w w .j av a 2 s .c om int size = getSize(); builder.append("\n"); builder.append("URL: "); builder.append(getUrl().toString()); builder.append("\n"); builder.append("Download size: "); if (size >= 0) { builder.append(FileUtils.byteCountToDisplaySize(size)); } else if (size == UNDEFINED) { builder.append(NLS.bind("Connecting to {0} to get the size...", getUrl().toString())); } else if (size == ERROR) { builder.append(NLS.bind("Unknown (unable to connect to {0})", getUrl().toString())); } return builder.toString(); }
From source file:io.github.dsheirer.gui.SDRTrunk.java
public SDRTrunk() { mLog.info("*******************************************************************"); mLog.info("**** sdrtrunk: a trunked radio and digital decoding application ***"); mLog.info("**** website: https://github.com/dsheirer/sdrtrunk ***"); mLog.info("*******************************************************************"); mLog.info("Memory Logging Format: [Used/Allocated PercentUsed%]"); mLog.info("Host CPU Cores: " + Runtime.getRuntime().availableProcessors()); mLog.info("Host OS Name: " + System.getProperty("os.name")); mLog.info("Host OS Arch: " + System.getProperty("os.arch")); mLog.info("Host OS Version: " + System.getProperty("os.version")); mLog.info("Host Max Java Memory: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory())); //Setup the application home directory Path home = getHomePath();/*from w w w . ja va 2 s. c om*/ ThreadPool.logSettings(); mLog.info("Home path: " + home.toString()); //Load properties file if (home != null) { loadProperties(home); } //Log current properties setting SystemProperties.getInstance().logCurrentSettings(); TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel(); TunerModel tunerModel = new TunerModel(tunerConfigurationModel); mIconManager = new IconManager(); mSettingsManager = new SettingsManager(tunerConfigurationModel); AliasModel aliasModel = new AliasModel(); ChannelModel channelModel = new ChannelModel(); ChannelMapModel channelMapModel = new ChannelMapModel(); EventLogManager eventLogManager = new EventLogManager(); RecorderManager recorderManager = new RecorderManager(); SourceManager sourceManager = new SourceManager(tunerModel, mSettingsManager); ChannelProcessingManager channelProcessingManager = new ChannelProcessingManager(channelModel, channelMapModel, aliasModel, eventLogManager, recorderManager, sourceManager); channelProcessingManager.addAudioPacketListener(recorderManager); channelModel.addListener(channelProcessingManager); ChannelSelectionManager channelSelectionManager = new ChannelSelectionManager(channelModel); channelModel.addListener(channelSelectionManager); AliasActionManager aliasActionManager = new AliasActionManager(); channelProcessingManager.addMessageListener(aliasActionManager); AudioManager audioManager = new AudioManager(sourceManager.getMixerManager()); channelProcessingManager.addAudioPacketListener(audioManager); mBroadcastModel = new BroadcastModel(mIconManager); channelProcessingManager.addAudioPacketListener(mBroadcastModel); MapService mapService = new MapService(mIconManager); channelProcessingManager.addMessageListener(mapService); mControllerPanel = new ControllerPanel(audioManager, aliasModel, mBroadcastModel, channelModel, channelMapModel, channelProcessingManager, mIconManager, mapService, mSettingsManager, sourceManager, tunerModel); mSpectralPanel = new SpectralDisplayPanel(channelModel, channelProcessingManager, mSettingsManager); TunerSpectralDisplayManager tunerSpectralDisplayManager = new TunerSpectralDisplayManager(mSpectralPanel, channelModel, channelProcessingManager, mSettingsManager); tunerModel.addListener(tunerSpectralDisplayManager); tunerModel.addListener(this); PlaylistManager playlistManager = new PlaylistManager(aliasModel, mBroadcastModel, channelModel, channelMapModel); playlistManager.init(); mLog.info("starting main application gui"); //Initialize the GUI initGUI(); tunerModel.requestFirstTunerDisplay(); //Start the gui EventQueue.invokeLater(new Runnable() { public void run() { try { mMainGui.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:com.github.lucapino.sheetmaker.parsers.mediainfo.MediaInfoExtractor.java
private void print(String rootPath) throws Exception { FileFilter filter = new FileFilter() { @Override/* ww w. j a va 2s. com*/ public boolean accept(File pathname) { String lowerCaseName = pathname.getName().toLowerCase(); return (lowerCaseName.endsWith("ifo") && lowerCaseName.startsWith("vts")) || lowerCaseName.endsWith("mkv") || lowerCaseName.endsWith("iso") || lowerCaseName.endsWith("avi"); } }; // parse all the tree under rootPath File rootFolder = new File(rootPath); File[] files = rootFolder.listFiles(); Arrays.sort(files); Map<File, List<File>> mediaMap = new TreeMap<>(); for (File file : files) { System.out.println(file.getName()); // name of the folder -> name of media List<File> fileList; if (file.isDirectory()) { fileList = recurseSubFolder(filter, file); if (!fileList.isEmpty()) { System.out.println("adding " + fileList); mediaMap.put(file, fileList); } } else { if (filter.accept(file)) { fileList = new ArrayList<>(); fileList.add(file); System.out.println("adding " + fileList); mediaMap.put(file, fileList); } } } Set<File> fileNamesSet = mediaMap.keySet(); File outputFile = new File("/home/tagliani/tmp/HD-report.xls"); Workbook wb = new HSSFWorkbook(new FileInputStream(outputFile)); Sheet sheet = wb.createSheet("Toshiba"); MediaInfo MI = new MediaInfo(); int j = 0; for (File mediaFile : fileNamesSet) { List<File> filesList = mediaMap.get(mediaFile); for (File fileInList : filesList) { List<String> audioTracks = new ArrayList<>(); List<String> videoTracks = new ArrayList<>(); List<String> subtitlesTracks = new ArrayList<>(); MI.Open(fileInList.getAbsolutePath()); String durationInt = MI.Get(MediaInfo.StreamKind.General, 0, "Duration", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); System.out.println(fileInList.getName() + " -> " + durationInt); if (StringUtils.isNotEmpty(durationInt) && Integer.valueOf(durationInt) >= 60 * 60 * 1000) { Row row = sheet.createRow(j); String duration = MI.Get(MediaInfo.StreamKind.General, 0, "Duration/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); // Create a cell and put a value in it. row.createCell(0).setCellValue(WordUtils.capitalizeFully(mediaFile.getName())); if (fileInList.getName().toLowerCase().endsWith("iso") || fileInList.getName().toLowerCase().endsWith("ifo")) { row.createCell(1).setCellValue("DVD"); } else { row.createCell(1) .setCellValue(FilenameUtils.getExtension(fileInList.getName()).toUpperCase()); } row.createCell(2).setCellValue(FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(mediaFile))); // row.createCell(3).setCellValue(fileInList.getAbsolutePath()); row.createCell(3).setCellValue(duration); // MPEG-2 720x576 @ 25fps 16:9 String format = MI.Get(MediaInfo.StreamKind.Video, 0, "Format", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(4).setCellValue(format); String width = MI.Get(MediaInfo.StreamKind.Video, 0, "Width", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String height = MI.Get(MediaInfo.StreamKind.Video, 0, "Height", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(5).setCellValue(width + "x" + height); String fps = MI.Get(MediaInfo.StreamKind.Video, 0, "FrameRate", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(6).setCellValue(fps); String aspectRatio = MI.Get(MediaInfo.StreamKind.Video, 0, "DisplayAspectRatio/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(7).setCellValue(aspectRatio); int audioStreamNumber = MI.Count_Get(MediaInfo.StreamKind.Audio); for (int i = 0; i < audioStreamNumber; i++) { String audioTitle = MI.Get(MediaInfo.StreamKind.Audio, i, "Title", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String language = MI.Get(MediaInfo.StreamKind.Audio, i, "Language/String3", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String codec = MI.Get(MediaInfo.StreamKind.Audio, i, "Codec", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String channels = MI.Get(MediaInfo.StreamKind.Audio, i, "Channel(s)", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String sampleRate = MI.Get(MediaInfo.StreamKind.Audio, i, "SamplingRate/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); // AC3 ITA 5.1 48.0KHz StringBuilder sb = new StringBuilder(); if (StringUtils.isEmpty(audioTitle)) { sb.append(codec).append(" ").append(language.toUpperCase()).append(" ") .append(channels); } else { sb.append(audioTitle); } sb.append(" ").append(sampleRate); audioTracks.add(sb.toString()); } int textStreamNumber = MI.Count_Get(MediaInfo.StreamKind.Text); for (int i = 0; i < textStreamNumber; i++) { String textLanguage = MI.Get(MediaInfo.StreamKind.Text, i, "Language/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); subtitlesTracks.add(textLanguage); } MI.Close(); row.createCell(8).setCellValue(audioTracks.toString()); row.createCell(9).setCellValue(subtitlesTracks.toString()); j++; } } // System.out.println(mediaName); } try (FileOutputStream fileOut = new FileOutputStream(outputFile)) { wb.write(fileOut); } }
From source file:com.us.action.file.KindUpLoad.java
@Override public void addActionError(String anErrorMessage) { if (anErrorMessage.startsWith(SIZE_LIMIT_EXCEPTION)) { Matcher m = Pattern.compile("\\d+").matcher(anErrorMessage); String s1 = "0"; if (m.find()) s1 = m.group();/*from w w w . j a va2 s . co m*/ String s2 = "0"; if (m.find()) s2 = m.group(); gloabelError = getI118("${upload.gtSysSet}", getRequest(), FileUtils.byteCountToDisplaySize(Long.parseLong(s1)), FileUtils.byteCountToDisplaySize(Long.parseLong(s2))); } else { super.addActionError(anErrorMessage); } }
From source file:ai.serotonin.backup.Backup.java
private File encryptFile(final File file) throws Exception { final SecureRandom random = new SecureRandom(); final byte[] salt = random.generateSeed(8); final String saltStr = Hex.encodeHexString(salt); final SecretKey secret = createSecretKey(salt); final Cipher cipher = createCipher(); cipher.init(Cipher.ENCRYPT_MODE, secret); final AlgorithmParameters params = cipher.getParameters(); final byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV(); final String ivStr = Hex.encodeHexString(iv); final File encryptedFile = new File(file.getParent(), saltStr + "_" + ivStr + "_" + file.getName()); cipherizeFile(file, encryptedFile, cipher); file.delete();//from w w w.j ava 2 s .c om LOG.info("Encrypted backup file to " + encryptedFile.getPath() + ", " + FileUtils.byteCountToDisplaySize(encryptedFile.length())); return encryptedFile; }
From source file:com.adaptris.core.DefaultSerializableMessageTranslator.java
private String buildFileDetails(File f) throws CoreException { String result = null;//from w w w . jav a2 s. co m try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); result = new ToStringBuilder(f, ToStringStyle.MULTI_LINE_STYLE).append("Path", f.getCanonicalPath()) .append("Size", FileUtils.byteCountToDisplaySize(f.length())) .append("LastModified", sdf.format(new Date(f.lastModified()))).toString(); } catch (Exception e) { ExceptionHelper.rethrowCoreException(e); } return result; }