Package org.appng.api
Enum FileUpload.Unit
- java.lang.Object
-
- java.lang.Enum<FileUpload.Unit>
-
- org.appng.api.FileUpload.Unit
-
- All Implemented Interfaces:
Serializable
,Comparable<FileUpload.Unit>
- Enclosing class:
- FileUpload
public static enum FileUpload.Unit extends Enum<FileUpload.Unit>
the unit to use for validating uploads by their size
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(long size, NumberFormat format)
Formats the given size using aNumberFormat
static String
format(FileUpload.Unit unit, long size, NumberFormat format)
Formats the given size of the givenFileUpload.Unit
using aNumberFormat
, appending the givenFileUpload.Unit
.
Example:long
getFactor()
the factor to multiply with to get the number of bytes per whole unitstatic FileUpload.Unit
valueOf(String name)
Returns the enum constant of this type with the specified name.static FileUpload.Unit[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
B
public static final FileUpload.Unit B
byte
-
KB
public static final FileUpload.Unit KB
kilobyte
-
MB
public static final FileUpload.Unit MB
megabyte
-
-
Method Detail
-
values
public static FileUpload.Unit[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (FileUpload.Unit c : FileUpload.Unit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static FileUpload.Unit valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
getFactor
public long getFactor()
the factor to multiply with to get the number of bytes per whole unit- Returns:
- the factor
-
format
public String format(long size, NumberFormat format)
Formats the given size using aNumberFormat
- Parameters:
size
- the size in bytesformat
- theNumberFormat
- Returns:
- the formatted size
- See Also:
format(FileUpload.Unit, long, NumberFormat)
-
format
public static String format(FileUpload.Unit unit, long size, NumberFormat format)
Formats the given size of the givenFileUpload.Unit
using aNumberFormat
, appending the givenFileUpload.Unit
.
Example:NumberFormat numberFormat = new DecimalFormat("0.0# ", new DecimalFormatSymbols(Locale.ENGLISH)); String format = Unit.format(Unit.MB, (long) (2.46d * 1024l * 1024l), numberFormat); org.junit.Assert.assertEquals("2.46 MB", format);
- Parameters:
unit
- theFileUpload.Unit
size
- the size in bytesformat
- theNumberFormat
- Returns:
- the formatted size
-
-