Java Code Examples for org.apache.commons.io.FileUtils#byteCountToDisplaySize()

The following examples show how to use org.apache.commons.io.FileUtils#byteCountToDisplaySize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatView.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
private void updateEnabledButtons() {
    ButtonStatus status = this.currentButtonStatus();

    boolean enabled = !(status == ButtonStatus.AttDisabled || status == ButtonStatus.Disabled);
    mSendButton.setEnabled(enabled);
    mTextComposingArea.getDropHandler().setDropEnabled(enabled);

    String tooltipText;
    switch (status) {
        case Attachment:
            mSendButton.setIcon(ATT_ICON);
            tooltipText = Tr.tr("Send File") + " - " + Tr.tr("max. size:") + " "
                    + FileUtils.byteCountToDisplaySize(AttachmentManager.MAX_ATT_SIZE);
            break;
        case AttDisabled:
            mSendButton.setIcon(ATT_ICON);
            tooltipText = Tr.tr("Sending files not supported by server");
            break;
        default:
            mSendButton.setIcon(SEND_ICON);
            tooltipText = Tr.tr("Send Message");
    }

    TooltipManager.setTooltip(mSendButton, tooltipText);
}
 
Example 2
Source File: SetReadableFileSize.java    From jesterj with Apache License 2.0 6 votes vote down vote up
@Override
public Document[] processDocument(Document document) {

  String val = document.getFirstValue(getInputField());
  if (StringUtils.isNotBlank(val)) {
    long lFileSize = Long.parseLong(val);

    String readableFileSize = FileUtils.byteCountToDisplaySize(lFileSize);

    if (StringUtils.isNotBlank(getNumericAndUnitsField())) {
      document.put(getNumericAndUnitsField(), readableFileSize);
    }
    String[] parts = readableFileSize.split(" ");
    if (StringUtils.isNotBlank(getUnitsField())) {
      document.put(getUnitsField(), parts[1]);
    }
    if (StringUtils.isNotBlank(getNumericField())) {
      document.put(getNumericField(), parts[0]);
    }
  }

  return new Document[]{document};
}
 
Example 3
Source File: RocksDBMetrics.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> getMetrics() {
    Map<String, Object> metrics = InsertionOrderUtil.newMap();
    metrics.put(NODES, 1);
    // NOTE: the unit of rocksdb mem property is bytes
    metrics.put(MEM_USED, this.getMemUsed() / Bytes.MB);
    metrics.put(MEM_UNIT, "MB");

    putMetrics(metrics, BLOCK_CACHE);
    putMetrics(metrics, BLOCK_CACHE_PINNED);
    putMetrics(metrics, BLOCK_CACHE_CAPACITY);
    putMetrics(metrics, INDEX_FILTER);
    putMetrics(metrics, ALL_MEM_TABLE);
    putMetrics(metrics, MEM_TABLE);
    putMetrics(metrics, MEM_TABLE_FLUSH_PENDINF);

    String size = FileUtils.byteCountToDisplaySize(this.getDataSize());
    metrics.put(DATA_SIZE, size);

    return metrics;
}
 
Example 4
Source File: DbxEntryRevision.java    From Open-LaTeX-Studio with MIT License 5 votes vote down vote up
public DbxEntryRevision(FileMetadata metadata) {
    name = metadata.getName();
    path = metadata.getPathDisplay();
    humanSize = FileUtils.byteCountToDisplaySize(metadata.getSize());
    lastModified = metadata.getServerModified();
    revision = metadata.getRev();
}
 
Example 5
Source File: PacketTablePanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get value for the given route point
 *
 * @param point
 * @return value
 */
public Object getValue(final AbstractPacketPoint point) {
	switch (this) {
	case NUMBER:
		return point.getNumber();
	case COUNTRY_FLAG:
		return point.getCountryFlag(Resolution.R16);
	case LOCATION:
		return getText(point);
	case PROTOCOL:
		return point.getProtocol();
	case DEST_IP:
		return point.getIp();
	case DEST_HOSTNAME:
		return point.getHostname();
	case DEST_PORT:
		return point.getDestPort();
	case SRC_PORT:
		return point.getSourcePort();
	case TIME:
		return point.getDate();
	case DATA_LENGTH:
		return FileUtils.byteCountToDisplaySize(point.getDataLength());
	case WHO_IS:
		return point.getIp();
	default:
		return null;
	}
}
 
Example 6
Source File: FileUtility.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts the size in bytes to display size
 * 
 * @param sizeInBytes
 * @return String
 */
public static String formatBytesSizeToDisplaySize(BigInteger sizeInBytes){
	if(sizeInBytes == null){
		return null;
	}else{
		return FileUtils.byteCountToDisplaySize(sizeInBytes);
	}
}
 
Example 7
Source File: ConfigRepository.java    From gocd with Apache License 2.0 4 votes vote down vote up
private String getConfigRepoDisplaySize() {
    return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(workingDir));
}
 
Example 8
Source File: PrivateMessagesTool.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getAttachmentReadableSize(final String attachmentSize) {
  return FileUtils.byteCountToDisplaySize(Long.parseLong(attachmentSize));
}
 
Example 9
Source File: RemoteFetcher.java    From tajo with Apache License 2.0 4 votes vote down vote up
@Override
public List<FileChunk> get() throws IOException {
  List<FileChunk> fileChunks = new ArrayList<>();

  if (state == FetcherState.FETCH_INIT) {
    ChannelInitializer<Channel> initializer = new HttpClientChannelInitializer(fileChunk.getFile());
    bootstrap.handler(initializer);
  }

  this.startTime = System.currentTimeMillis();
  this.state = FetcherState.FETCH_DATA_FETCHING;
  ChannelFuture future = null;
  try {
    future = bootstrap.clone().connect(new InetSocketAddress(host, port))
            .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);

    // Wait until the connection attempt succeeds or fails.
    Channel channel = future.awaitUninterruptibly().channel();
    if (!future.isSuccess()) {
      state = TajoProtos.FetcherState.FETCH_FAILED;
      throw new IOException(future.cause());
    }

    String query = uri.getPath()
        + (uri.getRawQuery() != null ? "?" + uri.getRawQuery() : "");
    // Prepare the HTTP request.
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, query);
    request.headers().set(HttpHeaders.Names.HOST, host);
    request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
    request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

    if(LOG.isDebugEnabled()) {
      LOG.debug("Status: " + getState() + ", URI:" + uri);
    }
    // Send the HTTP request.
    channel.writeAndFlush(request);

    // Wait for the server to close the connection. throw exception if failed
    channel.closeFuture().syncUninterruptibly();

    fileChunk.setLength(fileChunk.getFile().length());

    long start = 0;
    for (Long eachChunkLength : chunkLengths) {
      if (eachChunkLength == 0) continue;
      FileChunk chunk = new FileChunk(fileChunk.getFile(), start, eachChunkLength);
      chunk.setEbId(fileChunk.getEbId());
      chunk.setFromRemote(true);
      fileChunks.add(chunk);
      start += eachChunkLength;
    }
    return fileChunks;

  } finally {
    if(future != null && future.channel().isOpen()){
      // Close the channel to exit.
      future.channel().close().awaitUninterruptibly();
    }

    this.finishTime = System.currentTimeMillis();
    long elapsedMills = finishTime - startTime;
    String transferSpeed;
    if(elapsedMills > 1000) {
      long bytePerSec = (fileChunk.length() * 1000) / elapsedMills;
      transferSpeed = FileUtils.byteCountToDisplaySize(bytePerSec);
    } else {
      transferSpeed = FileUtils.byteCountToDisplaySize(Math.max(fileChunk.length(), 0));
    }

    LOG.info(String.format("Fetcher :%d ms elapsed. %s/sec, len:%d, state:%s, URL:%s",
        elapsedMills, transferSpeed, fileChunk.length(), getState(), uri));
  }
}
 
Example 10
Source File: BackupService.java    From gocd with Apache License 2.0 4 votes vote down vote up
public String availableDiskSpace() {
    File artifactsDir = artifactsDirHolder.getArtifactsDir();
    return FileUtils.byteCountToDisplaySize(artifactsDir.getUsableSpace());
}
 
Example 11
Source File: PrivateMessagesTool.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getAttachmentReadableSize(final String attachmentSize) {
  return FileUtils.byteCountToDisplaySize(Long.parseLong(attachmentSize));
}
 
Example 12
Source File: Informatons.java    From jease with GNU General Public License v3.0 4 votes vote down vote up
public static String getDatabaseSize() {
	return FileUtils.byteCountToDisplaySize(FileUtils
			.sizeOfDirectory(new File(getDatabaseDirectory())));
}
 
Example 13
Source File: JudgelsPlayUtils.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
public static String formatBytesCount(long bytes) {
    return FileUtils.byteCountToDisplaySize(bytes);
}
 
Example 14
Source File: FileInfoDialog.java    From turbo-editor with GNU General Public License v3.0 4 votes vote down vote up
@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"));
    }

    // 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();
}
 
Example 15
Source File: FeedParser.java    From sakai with Educational Community License v2.0 2 votes vote down vote up
/**
 * Helper to format the length from bytes into a human readable format eg 126 kB
 * @param length
 * @return
 */
private static String formatLength(long length){
	return FileUtils.byteCountToDisplaySize(length);
}
 
Example 16
Source File: FileStorage.java    From etf-webapp with European Union Public License 1.2 2 votes vote down vote up
/**
 * Change the max storage size
 *
 * @param maxStorageSize
 *            max storage size
 */
public void setMaxStorageSize(final long maxStorageSize) {
    this.maxStorageSize = maxStorageSize;
    this.maxStorageSizeHr = FileUtils.byteCountToDisplaySize(maxStorageSize);
}
 
Example 17
Source File: FS.java    From Jupiter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a human-readable version of the file size, where the input represents a specific file to measure.
 *
 * @param file file to measure
 */
public static String sizeToDisplay(File file) {
  return FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(file));
}
 
Example 18
Source File: StorageUnitConverter.java    From pentaho-kettle with Apache License 2.0 2 votes vote down vote up
/**
 * Converts byte count to the human readable representation. The size is rounded to nearest X-byte.
 * <p>
 * For example: 13.1MB in byte count will return 13MB and 13.9MB in byte count wil return 13MB.
 * <p>
 *  Supported types: EB, PB, TB, GB, MB, KB or B (for bytes).
 *
 * @param byteCount
 * @return human reabable display size
 */
public String byteCountToDisplaySize( long byteCount ) {
  String spacedDisplaySize = FileUtils.byteCountToDisplaySize( byteCount );
  return spacedDisplaySize.replace( "bytes", "B" ).replace( " ", "" );
}
 
Example 19
Source File: FeedParser.java    From sakai with Educational Community License v2.0 2 votes vote down vote up
/**
 * Helper to format the length from bytes into a human readable format eg 126 kB
 * @param length
 * @return
 */
private static String formatLength(long length){
	return FileUtils.byteCountToDisplaySize(length);
}
 
Example 20
Source File: StorageUnitConverter.java    From hop with Apache License 2.0 2 votes vote down vote up
/**
 * Converts byte count to the human readable representation. The size is rounded to nearest X-byte.
 * <p>
 * For example: 13.1MB in byte count will return 13MB and 13.9MB in byte count wil return 13MB.
 * <p>
 *  Supported types: EB, PB, TB, GB, MB, KB or B (for bytes).
 *
 * @param byteCount
 * @return human reabable display size
 */
public String byteCountToDisplaySize( long byteCount ) {
  String spacedDisplaySize = FileUtils.byteCountToDisplaySize( byteCount );
  return spacedDisplaySize.replace( "bytes", "B" ).replace( " ", "" );
}