Class ArrayUtil

java.lang.Object
org.apache.derby.iapi.services.io.ArrayUtil

public abstract class ArrayUtil extends Object
Utility class for constructing and reading and writing arrays from/to formatId streams and for performing other operations on arrays.
Version:
0.1
  • Field Details

    • EMPTY_BYTE_ARRAY

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

      @SafeVarargs 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.
    • writeArrayLength

      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 stream
      a - array of objects whose length should be written.
      Throws:
      IOException - The write caused an IOException.
    • writeArrayItems

      public static void writeArrayItems(ObjectOutput out, Object[] a) throws IOException
      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

      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 - 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 stream
      a - array to read into
      Throws:
      IOException - The write caused an IOException.
      ClassNotFoundException - The Class for an Object we are reading does not exist
    • readArrayLength

      public static int readArrayLength(ObjectInput in) throws IOException
      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

      public static Object[] readObjectArray(ObjectInput in) throws IOException, ClassNotFoundException
      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

      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 - the ObjectOutput.
      a - the array.
      Throws:
      IOException - The write caused an IOException.
    • readIntArray

      public static int[] readIntArray(ObjectInput in) throws IOException
      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

      public static void writeInts(ObjectOutput out, int[][] val) throws IOException
      Throws:
      IOException
    • readInts

      public static int[][] readInts(ObjectInput in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • toString

      public static String toString(int[] value)
    • writeLongArray

      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 - the ObjectOutput.
      a - the array.
      Throws:
      IOException - The write caused an IOException.
    • readLongArray

      public static long[] readLongArray(ObjectInput in) throws IOException
      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

      public static String[] readStringArray(ObjectInput in) throws IOException, ClassNotFoundException
      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

      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 - the ObjectOutput.
      a - the array.
      Throws:
      IOException - The write caused an IOException.
    • readBooleanArray

      public static boolean[] readBooleanArray(ObjectInput in) throws IOException
      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.