Package com.helger.commons.io.misc
Class SizeHelper
- java.lang.Object
-
- com.helger.commons.io.misc.SizeHelper
-
@NotThreadSafe public final class SizeHelper extends Object
A utility class that converts sizes into the corresponding Kilobyte, Megabyte etc. notation.
This class is not thread-safe, because theDecimalFormatclass is not thread-safe!- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringB_SUFFIXSuffix for Bytesstatic StringGB_SUFFIXSuffix for Gigabytesstatic StringKB_SUFFIXSuffix for Kilobytesstatic StringMB_SUFFIXSuffix for Megabytesstatic StringPB_SUFFIXSuffix for Petabytesstatic StringTB_SUFFIXSuffix for Terabytes
-
Constructor Summary
Constructors Constructor Description SizeHelper(DecimalFormatSymbols aDFS)SizeHelper(Locale aDisplayLocale)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAsGB(long nSize)StringgetAsGB(long nSize, int nDecimals)StringgetAsKB(long nSize)StringgetAsKB(long nSize, int nDecimals)StringgetAsMatching(long nSize)StringgetAsMatching(long nSize, int nDecimals)StringgetAsMatching(BigDecimal aSize)Get the best matching formatting of the passed value.StringgetAsMatching(BigDecimal aSize, int nDecimals)Get the best matching formatting of the passed value.StringgetAsMatching(BigInteger aSize)Get the best matching formatting of the passed value.StringgetAsMatching(BigInteger aSize, int nDecimals)Get the best matching formatting of the passed value.StringgetAsMB(long nSize)StringgetAsMB(long nSize, int nDecimals)StringgetAsPB(long nSize)StringgetAsPB(long nSize, int nDecimals)StringgetAsTB(long nSize)StringgetAsTB(long nSize, int nDecimals)static SizeHelpergetSizeHelperOfLocale(Locale aDisplayLocale)Get the size helper for the passed locale.StringtoString()
-
-
-
Field Detail
-
B_SUFFIX
public static final String B_SUFFIX
Suffix for Bytes- See Also:
- Constant Field Values
-
KB_SUFFIX
public static final String KB_SUFFIX
Suffix for Kilobytes- See Also:
- Constant Field Values
-
MB_SUFFIX
public static final String MB_SUFFIX
Suffix for Megabytes- See Also:
- Constant Field Values
-
GB_SUFFIX
public static final String GB_SUFFIX
Suffix for Gigabytes- See Also:
- Constant Field Values
-
TB_SUFFIX
public static final String TB_SUFFIX
Suffix for Terabytes- See Also:
- Constant Field Values
-
PB_SUFFIX
public static final String PB_SUFFIX
Suffix for Petabytes- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SizeHelper
public SizeHelper(@Nonnull DecimalFormatSymbols aDFS)
-
-
Method Detail
-
getAsKB
@Nonnull public String getAsKB(long nSize, @Nonnegative int nDecimals)
-
getAsMB
@Nonnull public String getAsMB(long nSize, @Nonnegative int nDecimals)
-
getAsGB
@Nonnull public String getAsGB(long nSize, @Nonnegative int nDecimals)
-
getAsTB
@Nonnull public String getAsTB(long nSize, @Nonnegative int nDecimals)
-
getAsPB
@Nonnull public String getAsPB(long nSize, @Nonnegative int nDecimals)
-
getAsMatching
@Nonnull public String getAsMatching(@Nonnull BigInteger aSize)
Get the best matching formatting of the passed value. No fraction digits will be emitted.- Parameters:
aSize- The value to be converted to a size value. May not benull.- Returns:
- The string representation
- Throws:
IllegalArgumentException- If the passed value cannot be fit in a long
-
getAsMatching
@Nonnull public String getAsMatching(@Nonnull BigInteger aSize, @Nonnegative int nDecimals)
Get the best matching formatting of the passed value.- Parameters:
aSize- The value to be converted to a size value. May not benull.nDecimals- The number of fraction digits.- Returns:
- The string representation
- Throws:
IllegalArgumentException- If the passed value cannot be fit in a long
-
getAsMatching
@Nonnull public String getAsMatching(@Nonnull BigDecimal aSize)
Get the best matching formatting of the passed value. No fraction digits will be emitted.- Parameters:
aSize- The value to be converted to a size value. May not benull.- Returns:
- The string representation
- Throws:
IllegalArgumentException- If the passed value cannot be fit in a long
-
getAsMatching
@Nonnull public String getAsMatching(@Nonnull BigDecimal aSize, @Nonnegative int nDecimals)
Get the best matching formatting of the passed value.- Parameters:
aSize- The value to be converted to a size value. May not benull.nDecimals- The number of fraction digits.- Returns:
- The string representation
- Throws:
IllegalArgumentException- If the passed value cannot be fit in a long
-
getAsMatching
@Nonnull public String getAsMatching(long nSize, @Nonnegative int nDecimals)
-
getSizeHelperOfLocale
@Nonnull public static SizeHelper getSizeHelperOfLocale(@Nonnull Locale aDisplayLocale)
Get the size helper for the passed locale. The locale determines the formatting of the numeric value.- Parameters:
aDisplayLocale- The locale to be used.- Returns:
- The non-
nullSizeHelperobject for the passed locale.
-
-