Class ArrayUtil
java.lang.Object
org.apache.derby.iapi.services.io.ArrayUtil
Utility class for constructing and reading and writing arrays from/to
formatId streams and for performing other operations on arrays.
- Version:
- 0.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]
An instance of an empty byte array. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List
<T> asReadOnlyList
(T... array) Make the contents of an array available as a read-only list.static boolean[]
copy
(boolean[] original) Copy a (possibly null) array of booleansstatic byte[]
copy
(byte[] original) Copy a (possibly null) array of bytesstatic int[]
copy
(int[] original) Copy a (possibly null) array of intsstatic long[]
copy
(long[] original) Copy a (possibly null) array of longsstatic <T> T[]
copy
(T[] original) Copy an array of objects; the original array could be nullstatic int[][]
copy2
(int[][] original) Copy a (possibly null) 2-dimensional array of intsstatic void
readArrayItems
(ObjectInput in, Object[] a) Read an array of objects out of a stream.static int
Read the length of an array of objects in an object stream.static boolean[]
Read an array of integers from an ObjectInput.static int[]
Read an array of integers from an ObjectInput.static int[][]
readInts
(ObjectInput in) static long[]
Read an array of integers from an ObjectInput.static Object[]
Reads an array of objects from the stream.static String[]
Read an array of strings from an ObjectInput.static String
toString
(int[] value) static void
writeArray
(ObjectOutput out, Object[] a) Write an array of objects and length to an output stream.static void
writeArrayItems
(ObjectOutput out, Object[] a) Write an array of objects to an output stream.static void
writeArrayLength
(ObjectOutput out, Object[] a) Write the length of an array of objects to an output stream.static void
writeBooleanArray
(ObjectOutput out, boolean[] a) Write an array of booleans to an ObjectOutput.static void
writeIntArray
(ObjectOutput out, int[] a) Write an array of integers to an ObjectOutput.static void
writeInts
(ObjectOutput out, int[][] val) static void
writeLongArray
(ObjectOutput out, long[] a) Write an array of longs to an ObjectOutput.
-
Field Details
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAYAn instance of an empty byte array. Since empty arrays are immutable, this instance can safely be shared. Code that needs an empty byte array can use this static instance instead of allocating a new one.
-
-
Constructor Details
-
ArrayUtil
public ArrayUtil()
-
-
Method Details
-
copy
public static <T> T[] copy(T[] original) Copy an array of objects; the original array could be null -
copy
public static boolean[] copy(boolean[] original) Copy a (possibly null) array of booleans -
copy
public static byte[] copy(byte[] original) Copy a (possibly null) array of bytes -
copy
public static int[] copy(int[] original) Copy a (possibly null) array of ints -
copy
public static long[] copy(long[] original) Copy a (possibly null) array of longs -
copy2
public static int[][] copy2(int[][] original) Copy a (possibly null) 2-dimensional array of ints -
asReadOnlyList
Make the contents of an array available as a read-only list. If the array is null, an empty list will be returned. -
writeArrayLength
Write the length of an array of objects to an output stream. The length- Parameters:
out
- ObjectOutput streama
- array of objects whose length should be written.- Throws:
IOException
- The write caused an IOException.
-
writeArrayItems
Write an array of objects to an output stream.- Parameters:
out
- Object output stream to write to.a
- array of objects to write.- Throws:
IOException
- The write caused an IOException.
-
writeArray
Write an array of objects and length to an output stream. Does equivalent of writeArrayLength() followed by writeArrayItems()- Parameters:
out
- Object output stream to write to.a
- array of objects to write.- Throws:
IOException
- The write caused an IOException.
-
readArrayItems
public static void readArrayItems(ObjectInput in, Object[] a) throws IOException, ClassNotFoundException Read an array of objects out of a stream.- Parameters:
in
- Input streama
- array to read into- Throws:
IOException
- The write caused an IOException.ClassNotFoundException
- The Class for an Object we are reading does not exist
-
readArrayLength
Read the length of an array of objects in an object stream.- Parameters:
in
- Input stream.- Returns:
- length of the array of objects
- Throws:
IOException
- The write caused an IOException.
-
readObjectArray
Reads an array of objects from the stream.- Parameters:
in
- Input stream- Throws:
IOException
- The write caused an IOException.ClassNotFoundException
- The Class for an Object we are reading does not exist
-
writeIntArray
Write an array of integers to an ObjectOutput. This writes the array in a format readIntArray understands.- Parameters:
out
- the ObjectOutput.a
- the array.- Throws:
IOException
- The write caused an IOException.
-
readIntArray
Read an array of integers from an ObjectInput. This allocates the array.- Parameters:
in
- the ObjectInput.- Returns:
- the array of integers.
- Throws:
IOException
- The write caused an IOException.
-
writeInts
- Throws:
IOException
-
readInts
- Throws:
IOException
ClassNotFoundException
-
toString
-
writeLongArray
Write an array of longs to an ObjectOutput. This writes the array in a format readLongArray understands.- Parameters:
out
- the ObjectOutput.a
- the array.- Throws:
IOException
- The write caused an IOException.
-
readLongArray
Read an array of integers from an ObjectInput. This allocates the array.- Parameters:
in
- the ObjectInput.- Returns:
- the array of integers.
- Throws:
IOException
- The write caused an IOException.
-
readStringArray
Read an array of strings from an ObjectInput. This allocates the array.- Parameters:
in
- the ObjectInput.- Returns:
- the array of integers.
- Throws:
IOException
- The write caused an IOException.ClassNotFoundException
-
writeBooleanArray
Write an array of booleans to an ObjectOutput. This writes the array in a format readBooleanArray understands.- Parameters:
out
- the ObjectOutput.a
- the array.- Throws:
IOException
- The write caused an IOException.
-
readBooleanArray
Read an array of integers from an ObjectInput. This allocates the array.- Parameters:
in
- the ObjectInput.- Returns:
- the array of integers.
- Throws:
IOException
- The write caused an IOException.
-