Class Allocator
- java.lang.Object
-
- org.apache.commons.imaging.common.Allocator
-
public class Allocator extends java.lang.ObjectChecks inputs for meeting allocation limits and allocates arrays.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCANONICAL_NAMEprivate static intDEFAULTOne GB.private static intLIMIT
-
Constructor Summary
Constructors Constructor Description Allocator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tapply(int request, java.util.function.IntFunction<T> factory)Allocates an Object of type T of the requested size.static <T> T[]array(int request, java.util.function.IntFunction<T[]> factory, int eltShallowByteSize)Allocates an array of type T of the requested size.static <T> java.util.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 intcheck(int request)Checks a request for meeting allocation limits.static intcheck(int request, int elementSize)Checks a request for meeting allocation limits.static intcheck(long request, int elementSize)Checks a request for meeting allocation limits.static intcheckByteArray(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.
-
-
-
Field Detail
-
CANONICAL_NAME
private static final java.lang.String CANONICAL_NAME
-
DEFAULT
private static final int DEFAULT
One GB.- See Also:
- Constant Field Values
-
LIMIT
private static final int LIMIT
-
-
Method Detail
-
apply
public static <T> T apply(int request, java.util.function.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, java.util.function.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> java.util.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)
-
-