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

- - ### Enum Constant Summary

    Enum Constants
    Enum Constant and Description
    `B` byte
    `KB` kilobyte
    `MB` megabyte

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `format(FileUpload.Unit unit, long size, NumberFormat format)` Formats the given size of the given `FileUpload.Unit` using a `NumberFormat`, appending the given `FileUpload.Unit`. Example:
    `String` | `format(long size, NumberFormat format)` Formats the given size using a `NumberFormat`
    `long` | `getFactor()` the factor to multiply with to get the number of bytes per whole unit
    `static 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.

    - ### Methods inherited from class java.lang.Enum

      `clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, wait, wait, wait`

- - ### 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 name
        `NullPointerException` - 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 a `NumberFormat`
      Parameters:
        `size` - the size in bytes
        `format` - the `NumberFormat`
      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 given `FileUpload.Unit` using a `NumberFormat`, appending the given `FileUpload.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` - the `FileUpload.Unit`
        `size` - the size in bytes
        `format` - the `NumberFormat`
      Returns:
        the formatted size

Copyright © 2011–2023 aiticon GmbH. All rights reserved.