Class FileSize
java.lang.Object
de.xima.fc.common.io.FileSize
- All Implemented Interfaces:
Serializable, Comparable<FileSize>
Data class for a file size, which can be given in bytes, kilobytes, megabytes etc.
- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionlongbytes()Gets the number of bytes.intbooleanFormats this file size in the closest unit of 10^3.Formats this file size in the closest unit of 2^10.longGB()Gets the number of GB, rounded to the nearest value. 1 GB = 1000^3 bytes.longGiB()Gets the number of GiB, rounded to the nearest value. 1 GiB = 1024^3 bytes.inthashCode()longkB()Gets the number of kB, rounded to the nearest value. 1 kB = 1000 bytes.longKiB()Gets the number of KiB, rounded to the nearest value. 1 KiB = 1024 bytes.longMB()Gets the number of MB, rounded to the nearest value. 1 MB = 1000^2 bytes.longMiB()Gets the number of MiB, rounded to the nearest value. 1 MiB = 1024^2 bytes.static FileSizeofBytes(long bytes) Creates a new FileSize object with the given number of bytes.static FileSizeofGB(long GB) Creates a new FileSize object with the given number of GB. 1 GB = 1000^3 bytes.static FileSizeofGiB(long GiB) Creates a new FileSize object with the given number of GiB. 1 GiB = 1024^3 bytes.static FileSizeofKB(long kB) Creates a new FileSize object with the given number of kB. 1 kB = 1000 bytes.static FileSizeofKiB(long KiB) Creates a new FileSize object with the given number of KiB. 1 KiB = 1024 bytes.static FileSizeofMB(long MB) Creates a new FileSize object with the given number of MB. 1 MB = 1000^2 bytes.static FileSizeofMiB(long MiB) Creates a new FileSize object with the given number of MiB. 1 MiB = 1024^2 bytes.static FileSizeofPB(long PB) Creates a new FileSize object with the given number of PB. 1 PB = 1000^5 bytes.static FileSizeofPiB(long PiB) Creates a new FileSize object with the given number of PiB. 1 PiB = 1024^5 bytes.static FileSizeofTB(long TB) Creates a new FileSize object with the given number of TB. 1 TB = 1000^4 bytes.static FileSizeofTiB(long TiB) Creates a new FileSize object with the given number of TiB. 1 TiB = 1024^4 bytes.longPB()Gets the number of PB, rounded to the nearest value. 1 PB = 1000^5 bytes.longPiB()Gets the number of PiB, rounded to the nearest value. 1 TiB = 1024^5 bytes.longTB()Gets the number of TB, rounded to the nearest value. 1 TB = 1000^4 bytes.longTiB()Gets the number of TiB, rounded to the nearest value. 1 TiB = 1024^4 bytes.toString()static FileSizezero()Gets a file size object representing zero bytes.static FileSizeGets a file size object representing zero bytes.
-
Method Details
-
GB
public long GB()Gets the number of GB, rounded to the nearest value. 1 GB = 1000^3 bytes.- Returns:
- The number of GB.
-
GiB
public long GiB()Gets the number of GiB, rounded to the nearest value. 1 GiB = 1024^3 bytes.- Returns:
- The number of GiB.
-
KiB
public long KiB()Gets the number of KiB, rounded to the nearest value. 1 KiB = 1024 bytes.- Returns:
- The number of KiB.
-
MB
public long MB()Gets the number of MB, rounded to the nearest value. 1 MB = 1000^2 bytes.- Returns:
- The number of MB.
-
MiB
public long MiB()Gets the number of MiB, rounded to the nearest value. 1 MiB = 1024^2 bytes.- Returns:
- The number of MiB.
-
PB
public long PB()Gets the number of PB, rounded to the nearest value. 1 PB = 1000^5 bytes.- Returns:
- The number of PB.
-
PiB
public long PiB()Gets the number of PiB, rounded to the nearest value. 1 TiB = 1024^5 bytes.- Returns:
- The number of PiB.
-
TB
public long TB()Gets the number of TB, rounded to the nearest value. 1 TB = 1000^4 bytes.- Returns:
- The number of TB.
-
TiB
public long TiB()Gets the number of TiB, rounded to the nearest value. 1 TiB = 1024^4 bytes.- Returns:
- The number of TiB.
-
bytes
public long bytes()Gets the number of bytes.- Returns:
- The number of bytes.
-
compareTo
- Specified by:
compareToin interfaceComparable<FileSize>
-
equals
-
formatClosest10
Formats this file size in the closest unit of 10^3. For example, 237kB or 12GB.- Returns:
- The formatted file size.
-
hashCode
-
kB
public long kB()Gets the number of kB, rounded to the nearest value. 1 kB = 1000 bytes.- Returns:
- The number of kB.
-
formatClosest2
Formats this file size in the closest unit of 2^10. For example, 37B, 237KiB or 12GiB.- Returns:
- The formatted file size.
-
toString
-
ofBytes
Creates a new FileSize object with the given number of bytes.- Parameters:
bytes- The number of bytes.- Returns:
- The new file size object.
-
ofGB
Creates a new FileSize object with the given number of GB. 1 GB = 1000^3 bytes.- Parameters:
GB- The number of GB.- Returns:
- The new file size object.
-
ofGiB
Creates a new FileSize object with the given number of GiB. 1 GiB = 1024^3 bytes.- Parameters:
GiB- The number of GiB.- Returns:
- The new file size object.
-
ofKB
Creates a new FileSize object with the given number of kB. 1 kB = 1000 bytes.- Parameters:
kB- The number of kB.- Returns:
- The new file size object.
-
ofKiB
Creates a new FileSize object with the given number of KiB. 1 KiB = 1024 bytes.- Parameters:
KiB- The number of KiB.- Returns:
- The new file size object.
-
ofMB
Creates a new FileSize object with the given number of MB. 1 MB = 1000^2 bytes.- Parameters:
MB- The number of MB.- Returns:
- The new file size object.
-
ofMiB
Creates a new FileSize object with the given number of MiB. 1 MiB = 1024^2 bytes.- Parameters:
MiB- The number of MiB.- Returns:
- The new file size object.
-
ofPB
Creates a new FileSize object with the given number of PB. 1 PB = 1000^5 bytes.- Parameters:
PB- The number of PB.- Returns:
- The new file size object.
-
ofPiB
Creates a new FileSize object with the given number of PiB. 1 PiB = 1024^5 bytes.- Parameters:
PiB- The number of PiB.- Returns:
- The new file size object.
-
ofTB
Creates a new FileSize object with the given number of TB. 1 TB = 1000^4 bytes.- Parameters:
TB- The number of TB.- Returns:
- The new file size object.
-
ofTiB
Creates a new FileSize object with the given number of TiB. 1 TiB = 1024^4 bytes.- Parameters:
TiB- The number of TiB.- Returns:
- The new file size object.
-
zero
Gets a file size object representing zero bytes.- Returns:
- The file size object.
-
zeroFileSize
Gets a file size object representing zero bytes.- Returns:
- The file size object.
-