List of usage examples for org.apache.commons.io FileUtils byteCountToDisplaySize
public static String byteCountToDisplaySize(long size)
From source file:com.github.abhinavmishra14.aws.glacier.service.test.GlacierVaultServiceTest.java
/** * Test get vault description./* w w w . j av a 2 s . co m*/ * * @throws Exception the exception */ @Test public void testGetVaultDescription() throws Exception { //Setup vault for test vaultService.createVault(VAULT_NAME); final DescribeVaultResult description = vaultService.getVaultDescription(VAULT_NAME); System.out.println("VaultNameFrmResponse: " + description.getVaultName()); System.out.println("No.Of archives: " + description.getNumberOfArchives()); System.out.println("Inventory lastUpdated: " + description.getLastInventoryDate()); System.out.println("SizeInBytes: " + FileUtils.byteCountToDisplaySize(description.getSizeInBytes())); System.out.println("VaultARN: " + description.getVaultARN()); assertEquals(VAULT_NAME, description.getVaultName()); }
From source file:com.adobe.acs.commons.util.impl.AbstractGuavaCacheMBean.java
@Override public final String getCacheSize() { // Iterate through the cache entries and compute the total size of byte array. long size = 0L; ConcurrentMap<K, V> cacheAsMap = getCache().asMap(); for (final Map.Entry<K, V> entry : cacheAsMap.entrySet()) { size += getBytesLength(entry.getValue()); }//w w w. j av a 2 s. co m // Convert bytes to human-friendly format return FileUtils.byteCountToDisplaySize(size); }
From source file:ai.serotonin.backup.Backup.java
private void createBackup(final File filename) throws Exception { LOG.info("Creating backup file " + filename); try (final FileOutputStream out = new FileOutputStream(filename); final ZipOutputStream zip = new ZipOutputStream(out)) { final JsonNode files = configRoot.get("files"); for (final JsonNode filesNode : files) { final String prefix = filesNode.get("prefix").asText(); final JsonNode paths = filesNode.get("paths"); for (final JsonNode path : paths) addFile(zip, prefix, path.asText()); }/*from ww w. ja v a 2 s . co m*/ } LOG.info("Created backup file " + filename + ", " + FileUtils.byteCountToDisplaySize(filename.length())); }
From source file:com.lovejoy777sarootool.rootool.adapters.BrowserListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder mViewHolder; int num_items = 0; final File file = new File(getItem(position)); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()); if (convertView == null) { convertView = mInflater.inflate(R.layout.item_browserlist, parent, false); mViewHolder = new ViewHolder(convertView); convertView.setTag(mViewHolder); } else {/* w w w . ja v a2 s . c o m*/ mViewHolder = (ViewHolder) convertView.getTag(); } if (Settings.mListAppearance > 0) { mViewHolder.dateview.setVisibility(TextView.VISIBLE); } else { mViewHolder.dateview.setVisibility(TextView.GONE); } // get icon IconPreview.getFileIcon(file, mViewHolder.icon); if (file.isFile()) { // Shows the size of File mViewHolder.bottomView.setText(FileUtils.byteCountToDisplaySize(file.length())); } else { String[] list = file.list(); if (list != null) num_items = list.length; // show the number of files in Folder mViewHolder.bottomView.setText(num_items + mResources.getString(R.string.files)); } mViewHolder.topView.setText(file.getName()); mViewHolder.dateview.setText(df.format(file.lastModified())); return convertView; }
From source file:com.maskyn.fileeditorpro.dialogfragment.FileInfoDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View view = new DialogHelper.Builder(getActivity()).setTitle(R.string.info) .setView(R.layout.dialog_fragment_file_info).createSkeletonView(); //final View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_fragment_file_info, null); ListView list = (ListView) view.findViewById(android.R.id.list); DocumentFile file = DocumentFile.fromFile( new File(AccessStorageApi.getPath(getActivity(), (Uri) getArguments().getParcelable("uri")))); if (file == null && Device.hasKitKatApi()) { file = DocumentFile.fromSingleUri(getActivity(), (Uri) getArguments().getParcelable("uri")); }//from www .ja va 2s . c om // Get the last modification information. Long lastModified = file.lastModified(); // Create a new date object and pass last modified information // to the date object. Date date = new Date(lastModified); String[] lines1 = { getString(R.string.name), //getString(R.string.folder), getString(R.string.size), getString(R.string.modification_date) }; String[] lines2 = { file.getName(), //file.getParent(), FileUtils.byteCountToDisplaySize(file.length()), date.toString() }; list.setAdapter(new AdapterTwoItem(getActivity(), lines1, lines2)); return new AlertDialog.Builder(getActivity()).setView(view) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); }
From source file:net.landora.video.filebrowser.FileTableModel.java
@Override public Object getValueAt(int rowIndex, int columnIndex) { VideoFile file = files.get(rowIndex); switch (columnIndex) { case COL_FILENAME: return file.getFile().getName(); case COL_STATUS: return file.getStatus(); case COL_SIZE: long length = file.getLength(); String display = FileUtils.byteCountToDisplaySize(length); return new Representation<Long>(display, length); case COL_VIDEO_INFO: VideoMetadata video = file.getVideo(); if (video == null) { return ""; } else {//from w ww .ja v a 2 s . co m return video.toString(); } default: return null; } }
From source file:com.tasktop.c2c.server.internal.wiki.server.domain.validation.AttachmentValidator.java
@Override public void validate(Object target, Errors errors) { Attachment attachment = (Attachment) target; ValidationUtils.rejectIfEmpty(errors, "page", "field.required"); ValidationUtils.rejectIfEmpty(errors, "name", "field.required"); if (attachment.getName() != null && !NAME_PATTERN.matcher(attachment.getName()).matches()) { errors.rejectValue("name", "invalidValue", new Object[] { attachment.getName() }, "invalid name"); }/*from w w w . ja va2 s . c o m*/ if (attachment.getMimeType() != null) { MediaType mediaType = null; try { mediaType = MediaType.parseMediaType(attachment.getMimeType()); } catch (IllegalArgumentException e) { errors.rejectValue("mimeType", "invalidFormat"); } if (mediaType != null) { if (mediaType.isWildcardType() || mediaType.isWildcardSubtype()) { errors.rejectValue("mimeType", "mediaTypeWildcardNotAllowed"); } else if (!mediaTypes.isSupported(mediaType)) { errors.rejectValue("mimeType", "mediaTypeNotPermissible", new Object[] { attachment.getMimeType() }, "bad mime type"); } } } if (attachment.getContent() == null || attachment.getContent().length == 0) { errors.rejectValue("content", "field.required"); } else { int attachementSize = attachment.getContent().length; if (attachementSize > configuration.getMaxAttachmentSize()) { errors.rejectValue("content", "field.tooLarge", new Object[] { FileUtils.byteCountToDisplaySize(configuration.getMaxAttachmentSize()) }, "Field to large"); } } }
From source file:com.junichi11.netbeans.modules.backlog.issue.ui.AttachmentPanel.java
public AttachmentPanel(Attachment attachment) { this.attachment = attachment; initComponents();/*from w w w .ja va 2s. c o m*/ namemLabel.setText(attachment.getName()); sizeLabel.setText(String.valueOf(FileUtils.byteCountToDisplaySize(attachment.getSize()))); User createdUser = attachment.getCreatedUser(); if (createdUser != null) { setToolTipText(String.format("Created by %s", createdUser.getName())); } else { openLinkButton.setVisible(false); downloadLinkButton.setVisible(false); } statusLabel.setText(""); // NOI18N }
From source file:com.checkmarx.jenkins.opensourceanalysis.ScanService.java
public OsaScanResult scan(boolean asynchronousScan) { OsaScanResult osaScanResult = new OsaScanResult(); FilePath sourceCodeZip = null;//from w ww . j a v a 2 s.c o m try { if (!validLicense()) { logger.error(NO_LICENSE_ERROR); osaScanResult.setIsOsaReturnedResult(false); return osaScanResult; } sourceCodeZip = zipOpenSourceCode(); if (asynchronousScan) { logger.info(OSA_RUN_SUBMITTED); scanSender.sendAsync(sourceCodeZip); return null; } else { logger.info(OSA_RUN_STARTED); scanSender.sendScanAndSetResults(sourceCodeZip, osaScanResult); logger.info(OSA_RUN_ENDED); scanResultsPresenter.printResultsToOutput(osaScanResult.getGetOpenSourceSummaryResponse()); } } catch (Zipper.MaxZipSizeReached zipSizeReached) { exposeZippingLogToJobConsole(zipSizeReached); logger.error("Open Source Analysis failed: When zipping file " + zipSizeReached.getCurrentZippedFileName() + ", reached maximum upload size limit of " + FileUtils.byteCountToDisplaySize(CxConfig.maxOSAZipSize()) + "\n"); } catch (Zipper.NoFilesToZip noFilesToZip) { exposeZippingLogToJobConsole(noFilesToZip); logger.error("Open Source Analysis failed: No files to scan"); } catch (Zipper.ZipperException zipException) { exposeZippingLogToJobConsole(zipException); logger.error("Open Source Analysis failed: " + zipException.getMessage(), zipException); } catch (Exception e) { logger.error("Open Source Analysis failed: " + e.getMessage(), e); } finally { //delete temp file if (sourceCodeZip != null) { deleteTemporaryFile(sourceCodeZip); } } return osaScanResult; }
From source file:com.dnielfe.manager.adapters.BrowserListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final ViewHolder mViewHolder; int num_items = 0; final File file = new File(getItem(position)); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.item_browserlist, parent, false); mViewHolder = new ViewHolder(convertView); convertView.setTag(mViewHolder); } else {//from ww w .java 2s. c om mViewHolder = (ViewHolder) convertView.getTag(); } if (Settings.mListAppearance > 0) { mViewHolder.dateview.setVisibility(TextView.VISIBLE); } else { mViewHolder.dateview.setVisibility(TextView.GONE); } if (Settings.showthumbnail) setIcon(file, mViewHolder.icon); else loadFromRes(file, mViewHolder.icon); if (file.isFile()) { // Shows the size of File mViewHolder.bottomView.setText(FileUtils.byteCountToDisplaySize(file.length())); } else { String[] list = file.list(); if (list != null) num_items = list.length; // show the number of files in Folder mViewHolder.bottomView.setText(num_items + mResources.getString(R.string.files)); } mViewHolder.topView.setText(file.getName()); mViewHolder.dateview.setText(df.format(file.lastModified())); return convertView; }