Class ByteArrayReadBuffer

All Implemented Interfaces:
ReadBuffer, ByteSequence, HashEncoded, Cloneable

public class ByteArrayReadBuffer extends AbstractByteArrayReadBuffer
A ReadBuffer on top of a byte array.
Author:
cp 2005.01.20
  • Constructor Details

    • ByteArrayReadBuffer

      protected ByteArrayReadBuffer()
      Default constructor provided for subclasses.
    • ByteArrayReadBuffer

      public ByteArrayReadBuffer(byte[] ab)
      Construct a ByteArrayReadBuffer object from a byte array. This constructor does not copy the byte array or make it private.
      Parameters:
      ab - an array of bytes
    • ByteArrayReadBuffer

      public ByteArrayReadBuffer(byte[] ab, int of, int cb)
      Construct a ByteArrayReadBuffer object from a portion of a byte array. This constructor does not copy the byte array or make it private.
      Parameters:
      ab - an array of bytes
      of - the offset into the byte array
      cb - the number of bytes to extract
    • ByteArrayReadBuffer

      public ByteArrayReadBuffer(byte[] ab, int of, int cb, boolean fCopy, boolean fPrivate, boolean fShallowClone)
      Construct a ByteArrayReadBuffer object from a portion of a byte array.
      Parameters:
      ab - an array of bytes
      of - the offset into the byte array
      cb - the number of bytes to extract
      fCopy - true to make a copy of the passed array
      fPrivate - true to treat the passed array as private data
      fShallowClone - true to allow cloning without copying the underlying byte[]
  • Method Details

    • resetRange

      public final void resetRange(int of, int cb)
      Reset the portion of the byte array the ReadBuffer operates upon.
      Overrides:
      resetRange in class AbstractByteArrayReadBuffer
      Parameters:
      of - an offset into the byte array
      cb - the number of bytes to utilize
    • getRawByteArray

      public final byte[] getRawByteArray()
      Obtain the byte array that this ReadBuffer uses. If the underlying byte array is private, then this method will always return a copy of the portion of the byte array that this ReadBuffer represents as if the called had called AbstractReadBuffer.toByteArray().
      Returns:
      the byte array that this ReadBuffer uses
    • getRawOffset

      public final int getRawOffset()
      Determine the offset into the byte array returned from getRawByteArray() that this ReadBuffer uses. If the underlying byte array is private, then this method will always return zero because getRawByteArray() will always return a copy of the portion of the byte array that this ReadBuffer represents.
      Returns:
      the offset into the raw byte array that this ReadBuffer uses
    • instantiateReadBuffer

      protected final ReadBuffer instantiateReadBuffer(int of, int cb)
      Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.
      Specified by:
      instantiateReadBuffer in class AbstractReadBuffer
      Parameters:
      of - the beginning index, inclusive
      cb - the number of bytes to include in the resulting ReadBuffer
      Returns:
      a ReadBuffer that represents a portion of this ReadBuffer
    • clone

      public Object clone()
      Create a clone of this ReadBuffer object.
      Specified by:
      clone in interface ReadBuffer
      Overrides:
      clone in class AbstractReadBuffer
      Returns:
      a ReadBuffer object with the same contents as this ReadBuffer object
    • toString

      public String toString()
      Provide a human-readable representation of the Binary object.
      Overrides:
      toString in class Object
      Returns:
      a String whose contents represent the value of this Binary object
    • isByteArrayPrivate

      protected final boolean isByteArrayPrivate()
      Determine if the underlying byte[] should be treated as private data.
      Specified by:
      isByteArrayPrivate in class AbstractByteArrayReadBuffer
      Returns:
      true iff the underlying data should not ever be exposed by this object
    • isShallowCloneable

      protected final boolean isShallowCloneable()
      Determine whether a clone can be made without cloning the byte array.
      Returns:
      true iff the underlying data can be shared by multiple instances of the ByteArrayReadBuffer class