Top Description Fields Constructors Methods
org.apache.derby.shared.common.util

public abstract Class ArrayUtil

extends Object
Class Inheritance
Imports
java.io.ObjectOutput, .ObjectInput, .IOException, java.util.Arrays, .Collections, .List

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

Modifier and TypeField and Description
public static final byte[]
EMPTY_BYTE_ARRAY

An instance of an empty byte array.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <
The type of the array cells
T
>
List<T>

Returns:

a read-only list
asReadOnlyList
(T...
The array to turn into a read-only list
array
)

Make the contents of an array available as a read-only list.

public static <
The type of the array cells
T
>
T[]

Returns:

a copy of the array
copy
(T[]
The original array to copy
original
)

Copy an array of objects; the original array could be null

public static boolean[]

Returns:

a copy of the array
copy
(boolean[]
The original array to copy
original
)

Copy a (possibly null) array of booleans

public static byte[]

Returns:

a copy of the array
copy
(byte[]
The original array to copy
original
)

Copy a (possibly null) array of bytes

public static int[]

Returns:

a copy of the array
copy
(int[]
The original array to copy
original
)

Copy a (possibly null) array of ints

public static long[]

Returns:

a copy of the array
copy
(long[]
The original array to copy
original
)

Copy a (possibly null) array of longs

public static int[][]

Returns:

a copy of the array
copy2
(int[][]
The original array to copy
original
)

Copy a (possibly null) 2-dimensional array of ints

public static void
readArrayItems(ObjectInput
Input stream
in
,
Object[]
array to read into
a
)

Read an array of objects out of a stream.

public static int

Returns:

length of the array of objects
readArrayLength
(ObjectInput
Input stream.
in
)

Read the length of an array of objects in an object stream.

public static boolean[]

Returns:

the array of integers.
readBooleanArray
(ObjectInput
the ObjectInput.
in
)

Read an array of integers from an ObjectInput.

public static int[]

Returns:

the array of integers.
readIntArray
(ObjectInput
the ObjectInput.
in
)

Read an array of integers from an ObjectInput.

public static int[][]
public static long[]

Returns:

the array of integers.
readLongArray
(ObjectInput
the ObjectInput.
in
)

Read an array of integers from an ObjectInput.

public static Object[]

Returns:

the array of objects
readObjectArray
(ObjectInput
Input stream
in
)

Reads an array of objects from the stream.

public static String[]

Returns:

the array of integers.
readStringArray
(ObjectInput
the ObjectInput.
in
)

Read an array of strings from an ObjectInput.

public static String
toString(int[] value)

public static void
writeArray(ObjectOutput
Object output stream to write to.
out
,
Object[]
array of objects to write.
a
)

Write an array of objects and length to an output stream.

public static void
writeArrayItems(ObjectOutput
Object output stream to write to.
out
,
Object[]
array of objects to write.
a
)

Write an array of objects to an output stream.

public static void
writeArrayLength(ObjectOutput
ObjectOutput stream
out
,
Object[]
array of objects whose length should be written.
a
)

Write the length of an array of objects to an output stream.

public static void
writeBooleanArray(ObjectOutput
the ObjectOutput.
out
,
boolean[]
the array.
a
)

Write an array of booleans to an ObjectOutput.

public static void
writeIntArray(ObjectOutput
the ObjectOutput.
out
,
int[]
the array.
a
)

Write an array of integers to an ObjectOutput.

public static void
writeInts(ObjectOutput out, int[][] val)

public static void
writeLongArray(ObjectOutput
the ObjectOutput.
out
,
long[]
the array.
a
)

Write an array of longs to an ObjectOutput.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_BYTE_ARRAYback to summary
public static final byte[] EMPTY_BYTE_ARRAY

An 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 Detail

ArrayUtilback to summary
public ArrayUtil()

Method Detail

asReadOnlyListback to summary
public static <T> List<T> asReadOnlyList(T... array)

Make the contents of an array available as a read-only list. If the array is null, an empty list will be returned.

Parameters
<T>
The type of the array cells
array:T[]

The array to turn into a read-only list

Returns:List<T>

a read-only list

Annotations
@SafeVarargs
copyback to summary
public static <T> T[] copy(T[] original)

Copy an array of objects; the original array could be null

Parameters
<T>
The type of the array cells
original:T[]

The original array to copy

Returns:T[]

a copy of the array

copyback to summary
public static boolean[] copy(boolean[] original)

Copy a (possibly null) array of booleans

Parameters
original:boolean[]

The original array to copy

Returns:boolean[]

a copy of the array

copyback to summary
public static byte[] copy(byte[] original)

Copy a (possibly null) array of bytes

Parameters
original:byte[]

The original array to copy

Returns:byte[]

a copy of the array

copyback to summary
public static int[] copy(int[] original)

Copy a (possibly null) array of ints

Parameters
original:int[]

The original array to copy

Returns:int[]

a copy of the array

copyback to summary
public static long[] copy(long[] original)

Copy a (possibly null) array of longs

Parameters
original:long[]

The original array to copy

Returns:long[]

a copy of the array

copy2back to summary
public static int[][] copy2(int[][] original)

Copy a (possibly null) 2-dimensional array of ints

Parameters
original:int[][]

The original array to copy

Returns:int[][]

a copy of the array

readArrayItemsback to summary
public static void readArrayItems(ObjectInput in, Object[] a) throws IOException, ClassNotFoundException

Read an array of objects out of a stream.

Parameters
in:ObjectInput

Input stream

a:Object[]

array to read into

Exceptions
IOException:
The write caused an IOException.
ClassNotFoundException:
The Class for an Object we are reading does not exist
readArrayLengthback to summary
public static int readArrayLength(ObjectInput in) throws IOException

Read the length of an array of objects in an object stream.

Parameters
in:ObjectInput

Input stream.

Returns:int

length of the array of objects

Exceptions
IOException:
The write caused an IOException.
readBooleanArrayback to summary
public static boolean[] readBooleanArray(ObjectInput in) throws IOException

Read an array of integers from an ObjectInput. This allocates the array.

Parameters
in:ObjectInput

the ObjectInput.

Returns:boolean[]

the array of integers.

Exceptions
IOException:
The write caused an IOException.
readIntArrayback to summary
public static int[] readIntArray(ObjectInput in) throws IOException

Read an array of integers from an ObjectInput. This allocates the array.

Parameters
in:ObjectInput

the ObjectInput.

Returns:int[]

the array of integers.

Exceptions
IOException:
The write caused an IOException.
readIntsback to summary
public static int[][] readInts(ObjectInput in) throws IOException, ClassNotFoundException
readLongArrayback to summary
public static long[] readLongArray(ObjectInput in) throws IOException

Read an array of integers from an ObjectInput. This allocates the array.

Parameters
in:ObjectInput

the ObjectInput.

Returns:long[]

the array of integers.

Exceptions
IOException:
The write caused an IOException.
readObjectArrayback to summary
public static Object[] readObjectArray(ObjectInput in) throws IOException, ClassNotFoundException

Reads an array of objects from the stream.

Parameters
in:ObjectInput

Input stream

Returns:Object[]

the array of objects

Exceptions
IOException:
The write caused an IOException.
ClassNotFoundException:
The Class for an Object we are reading does not exist
readStringArrayback to summary
public static String[] readStringArray(ObjectInput in) throws IOException, ClassNotFoundException

Read an array of strings from an ObjectInput. This allocates the array.

Parameters
in:ObjectInput

the ObjectInput.

Returns:String[]

the array of integers.

Exceptions
IOException:
The write caused an IOException.
ClassNotFoundException:
On error
toStringback to summary
public static String toString(int[] value)
writeArrayback to summary
public static void writeArray(ObjectOutput out, Object[] a) throws IOException

Write an array of objects and length to an output stream. Does equivalent of writeArrayLength() followed by writeArrayItems()

Parameters
out:ObjectOutput

Object output stream to write to.

a:Object[]

array of objects to write.

Exceptions
IOException:
The write caused an IOException.
writeArrayItemsback to summary
public static void writeArrayItems(ObjectOutput out, Object[] a) throws IOException

Write an array of objects to an output stream.

Parameters
out:ObjectOutput

Object output stream to write to.

a:Object[]

array of objects to write.

Exceptions
IOException:
The write caused an IOException.
writeArrayLengthback to summary
public static void writeArrayLength(ObjectOutput out, Object[] a) throws IOException

Write the length of an array of objects to an output stream. The length

Parameters
out:ObjectOutput

ObjectOutput stream

a:Object[]

array of objects whose length should be written.

Exceptions
IOException:
The write caused an IOException.
writeBooleanArrayback to summary
public static void writeBooleanArray(ObjectOutput out, boolean[] a) throws IOException

Write an array of booleans to an ObjectOutput. This writes the array in a format readBooleanArray understands.

Parameters
out:ObjectOutput

the ObjectOutput.

a:boolean[]

the array.

Exceptions
IOException:
The write caused an IOException.
writeIntArrayback to summary
public static void writeIntArray(ObjectOutput out, int[] a) throws IOException

Write an array of integers to an ObjectOutput. This writes the array in a format readIntArray understands.

Parameters
out:ObjectOutput

the ObjectOutput.

a:int[]

the array.

Exceptions
IOException:
The write caused an IOException.
writeIntsback to summary
public static void writeInts(ObjectOutput out, int[][] val) throws IOException
writeLongArrayback to summary
public static void writeLongArray(ObjectOutput out, long[] a) throws IOException

Write an array of longs to an ObjectOutput. This writes the array in a format readLongArray understands.

Parameters
out:ObjectOutput

the ObjectOutput.

a:long[]

the array.

Exceptions
IOException:
The write caused an IOException.