Class ByteArray

java.lang.Object
org.apache.derby.iapi.util.ByteArray

public final class ByteArray extends Object
ByteArray wraps java byte arrays (byte[]) to allow byte arrays to be used as keys in hashtables. This is required because the equals function on byte[] directly uses reference equality.

This class also allows the trio of array, offset and length to be carried around as a single object.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
     
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ByteArray(byte[] array)
     
    ByteArray(byte[] array, int offset, int length)
    Create an instance of this class that wraps ths given array.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static boolean
    equals(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength)
    Compare two byte arrays using value equality.
    boolean
    equals(Object other)
    Value equality for byte arrays.
    final byte[]
     
    final int
     
    final int
     
    int
     
    void
    Read this object from a stream of stored objects.
    void
    setBytes(byte[] array)
     
    void
    setBytes(byte[] array, int length)
     
    void
    setBytes(byte[] array, int offset, int length)
     
    final void
    setLength(int newLength)
     
    void
    Write the byte array out w/o compression

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • array

      private byte[] array
    • offset

      private int offset
    • length

      private int length
  • Constructor Details

    • ByteArray

      public ByteArray(byte[] array, int offset, int length)
      Create an instance of this class that wraps ths given array. This class does not make a copy of the array, it just saves the reference.
    • ByteArray

      public ByteArray(byte[] array)
    • ByteArray

      public ByteArray()
  • Method Details

    • setBytes

      public void setBytes(byte[] array)
    • setBytes

      public void setBytes(byte[] array, int length)
    • setBytes

      public void setBytes(byte[] array, int offset, int length)
    • equals

      public boolean equals(Object other)
      Value equality for byte arrays.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getArray

      public final byte[] getArray()
    • getOffset

      public final int getOffset()
    • getLength

      public final int getLength()
    • setLength

      public final void setLength(int newLength)
    • readExternal

      public void readExternal(ObjectInput in) throws IOException
      Read this object from a stream of stored objects.
      Parameters:
      in - read this.
      Throws:
      IOException - thrown on error
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Write the byte array out w/o compression
      Parameters:
      out - write bytes here.
      Throws:
      IOException - thrown on error
    • equals

      private static boolean equals(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength)
      Compare two byte arrays using value equality. Two byte arrays are equal if their length is identical and their contents are identical.