Package org.apache.commons.imaging.common

# Class Allocator

java.lang.Object
org.apache.commons.imaging.common.Allocator

public class Allocator extends Object
Checks inputs for meeting allocation limits and allocates arrays.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Allocator()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> T`
  `apply(int request, IntFunction<T> factory)`
  Allocates an Object of type T of the requested size.
  `static <T> T[]`
  `array(int request, IntFunction<T[]> factory, int eltShallowByteSize)`
  Allocates an array of type T of the requested size.
  `static <T> ArrayList<T>`
  `arrayList(int request)`
  Allocates an Object array of type T of the requested size.
  `static byte[]`
  `byteArray(int request)`
  Allocates a byte array of the requested size.
  `static byte[]`
  `byteArray(long request)`
  Allocates a byte array of the requested size.
  `static char[]`
  `charArray(int request)`
  Allocates a char array of the requested size.
  `static int`
  `check(int request)`
  Checks a request for meeting allocation limits.
  `static int`
  `check(int request, int elementSize)`
  Checks a request for meeting allocation limits.
  `static int`
  `check(long request, int elementSize)`
  Checks a request for meeting allocation limits.
  `static int`
  `checkByteArray(int request)`
  Checks that allocating a byte array of the requested size is within the limit.
  `static double[]`
  `doubleArray(int request)`
  Allocates a double array of the requested size.
  `static float[]`
  `floatArray(int request)`
  Allocates a float array of the requested size.
  `static int[]`
  `intArray(int request)`
  Allocates a int array of the requested size.
  `static long[]`
  `longArray(int request)`
  Allocates a long array of the requested size.
  `static short[]`
  `shortArray(int request)`
  Allocates a short array of the requested size.

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

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Allocator

    public Allocator()

- ## Method Details

  - ### apply

    public static <T> T apply(int request, IntFunction<T> factory)
    Allocates an Object of type T of the requested size.
    Type Parameters:
      `T` - The return array type
    Parameters:
      `request` - The requested size.
      `factory` - The array factory.
    Returns:
      a new byte array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int)`

  - ### array

    public static <T> T[] array(int request, IntFunction<T[]> factory, int eltShallowByteSize)
    Allocates an array of type T of the requested size.
    Type Parameters:
      `T` - The return array type
    Parameters:
      `request` - The requested size.
      `factory` - The array factory.
      `eltShallowByteSize` - The shallow byte size of an element.
    Returns:
      a new byte array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int)`

  - ### arrayList

    public static <T> ArrayList<T> arrayList(int request)
    Allocates an Object array of type T of the requested size.
    Type Parameters:
      `T` - The return array type
    Parameters:
      `request` - The requested size.
    Returns:
      a new byte array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int)`

  - ### byteArray

    public static byte[] byteArray(int request)
    Allocates a byte array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new byte array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### byteArray

    public static byte[] byteArray(long request)
    Allocates a byte array of the requested size.
    Parameters:
      `request` - The requested size is cast down to an int.
    Returns:
      a new byte array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### charArray

    public static char[] charArray(int request)
    Allocates a char array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new char array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### check

    public static int check(int request)
    Checks a request for meeting allocation limits.

    The default limit is `#DEFAULT`, override with the system property "org.apache.commons.imaging.common.mylzw.AllocationChecker".

    Parameters:
      `request` - an allocation request.
    Returns:
      the request.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.

  - ### check

    public static int check(int request, int elementSize)
    Checks a request for meeting allocation limits.

    The default limit is `#DEFAULT`, override with the system property "org.apache.commons.imaging.common.mylzw.AllocationChecker".

    Parameters:
      `request` - an allocation request count.
      `elementSize` - The element size.
    Returns:
      the request.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.

  - ### check

    public static int check(long request, int elementSize)
    Checks a request for meeting allocation limits.

    The default limit is `#DEFAULT`, override with the system property "org.apache.commons.imaging.common.mylzw.AllocationChecker".

    Parameters:
      `request` - an allocation request count is cast down to an int.
      `elementSize` - The element size.
    Returns:
      the request.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.

  - ### checkByteArray

    public static int checkByteArray(int request)
    Checks that allocating a byte array of the requested size is within the limit.
    Parameters:
      `request` - The byte array size.
    Returns:
      The input request.

  - ### doubleArray

    public static double[] doubleArray(int request)
    Allocates a double array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new double array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### floatArray

    public static float[] floatArray(int request)
    Allocates a float array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new float array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### intArray

    public static int[] intArray(int request)
    Allocates a int array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new int array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### longArray

    public static long[] longArray(int request)
    Allocates a long array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new long array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`

  - ### shortArray

    public static short[] shortArray(int request)
    Allocates a short array of the requested size.
    Parameters:
      `request` - The requested size.
    Returns:
      a new short array.
    Throws:
      `AllocationRequestException` - Thrown when the request exceeds the limit.
    See Also:
      - `check(int, int)`