public class

FileSize

extends Object
java.lang.Object
   ↳ com.atlassian.core.util.FileSize

Class Overview

A class that contains utility methods for formatting the size of files into human readable form.

Summary

Public Constructors
FileSize()
Public Methods
static String format(Long filesize)
Convenience method.
static String format(long filesize)
Format the size of a file in human readable form.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public FileSize ()

Public Methods

public static String format (Long filesize)

Convenience method. Calls format(long filesize).

Parameters
filesize The size of the file in bytes.
Returns
  • The size in human readable form.
See Also

public static String format (long filesize)

Format the size of a file in human readable form. Anything less than a kilobyte is presented in kilobytes to one decimal place. Anything between a kilobyte and a megabyte is presented in kilobytes to zero decimal places. Anything greater than one megabyte is presented in megabytes to two decimal places.

eg.

  • format(512) -> 0.5 kb
  • format(1024) -> 1.0 kb
  • format(2048) -> 2 kb
  • format(1024 * 400) -> 400 kb
  • format(1024 * 1024) -> 1024 kb
  • format(1024 * 1024 * 1.2) -> 1.20 Mb
  • format(1024 * 1024 * 20) -> 20.00 Mb
Parameters
filesize The size of the file in bytes.
Returns
  • The size in human readable form.