Package db

Class DBBuffer

java.lang.Object
db.DBBuffer

public class DBBuffer extends Object
DBBuffer facilitates synchronized access to a ChainedBuffer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(DBBuffer buffer)
    Append the contents of the specified dbBuf onto the end of this buffer.
    void
    Delete and release all underlying DataBuffers.
    void
    fill(int startOffset, int endOffset, byte fillByte)
    Fill the buffer over the specified range with a byte value.
    void
    Fill buffer with data provided by InputStream.
    void
    get(int offset, byte[] data)
    Get the byte data located at the specified offset.
    void
    get(int offset, byte[] data, int dataOffset, int length)
    Get the byte data located at the specified offset and store into the data array at the specified data offset.
    byte
    getByte(int offset)
    Get the 8-bit byte value located at the specified offset.
    int
    Get the first buffer ID associated with this chained buffer.
    int
    Returns the length;
    void
    put(int offset, byte[] bytes)
    Put the bytes provided into the buffer at the specified offset.
    void
    put(int offset, byte[] bytes, int dataOffset, int length)
    Put a specified number of bytes from the array provided into the buffer at the specified offset.
    void
    putByte(int offset, byte b)
    Put the 8-bit byte value into the buffer at the specified offset.
    void
    setSize(int size, boolean preserveData)
    Set the new size for this DBBuffer object.
    split(int offset)
    Split this DBBuffer object into two separate DBBuffers.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • split

      public DBBuffer split(int offset) throws IndexOutOfBoundsException, IOException
      Split this DBBuffer object into two separate DBBuffers. This DBBuffer remains valid but its new size is equal offset. The newly created DBBuffer is returned.
      Parameters:
      offset - the split point. The byte at this offset becomes the first byte within the new buffer.
      Returns:
      the new DBBuffer object.
      Throws:
      IndexOutOfBoundsException - if offset is invalid.
      IOException - thrown if an IO error occurs
    • setSize

      public void setSize(int size, boolean preserveData) throws IOException
      Set the new size for this DBBuffer object.
      Parameters:
      size - new size
      preserveData - if true, existing data is preserved at the original offsets. If false, no additional effort will be expended to preserve data.
      Throws:
      UnsupportedOperationException - thrown if this ChainedBuffer utilizes an Uninitialized Data Source or is read-only
      IOException - thrown if an IO error occurs.
    • length

      public int length()
      Returns the length;
      Returns:
      this buffers length
    • getId

      public int getId()
      Get the first buffer ID associated with this chained buffer. This DBBuffer may be reinstatiated using the returned buffer ID provided subsequent changes are not made.
      Returns:
      buffer ID
    • fill

      public void fill(int startOffset, int endOffset, byte fillByte) throws IndexOutOfBoundsException, IOException
      Fill the buffer over the specified range with a byte value.
      Parameters:
      startOffset - starting offset, inclusive
      endOffset - ending offset, exclusive
      fillByte - byte value
      Throws:
      IndexOutOfBoundsException - if an invalid offsets are provided or the end of buffer was encountered while storing the data.
      IOException - thrown if an IO error occurs
    • append

      public void append(DBBuffer buffer) throws IOException
      Append the contents of the specified dbBuf onto the end of this buffer. The size of this buffer increases by the size of dbBuf. When the operation is complete, dbBuf object is no longer valid and must not be used.
      Parameters:
      buffer - the buffer to be appended to this buffer.
      Throws:
      UnsupportedOperationException - if read-only, uninitialized data source is used, or both buffers do not have the same obfuscation enablement
      IOException - thrown if an IO error occurs
    • getByte

      public byte getByte(int offset) throws IndexOutOfBoundsException, IOException
      Get the 8-bit byte value located at the specified offset.
      Parameters:
      offset - byte offset from start of buffer.
      Returns:
      the byte value at the specified offset.
      Throws:
      IndexOutOfBoundsException - is thrown if an invalid offset is specified.
      IOException - is thrown if an error occurs while accessing the underlying storage.
    • get

      public void get(int offset, byte[] data, int dataOffset, int length) throws IndexOutOfBoundsException, IOException
      Get the byte data located at the specified offset and store into the data array at the specified data offset.
      Parameters:
      offset - byte offset from the start of the buffer.
      data - byte array to store the data.
      dataOffset - offset into the data buffer
      length - amount of data to read
      Throws:
      IndexOutOfBoundsException - if an invalid offset, dataOffset, or length is specified.
      IOException - is thrown if an error occurs while accessing the underlying storage.
    • fill

      public void fill(InputStream in) throws IOException
      Fill buffer with data provided by InputStream. If stream is exhausted, the remainder of the buffer will be filled with 0's.
      Parameters:
      in - data source
      Throws:
      IOException - thrown if IO error occurs.
    • put

      public void put(int offset, byte[] bytes, int dataOffset, int length) throws IndexOutOfBoundsException, IOException
      Put a specified number of bytes from the array provided into the buffer at the specified offset. The number of bytes stored is specified by the length specified.
      Parameters:
      offset - byte offset from start of buffer.
      bytes - the byte data to be stored.
      dataOffset - the starting offset into the data.
      length - the number of bytes to be stored.
      Throws:
      IndexOutOfBoundsException - if an invalid offset is provided or the end of buffer was encountered while storing the data.
      IOException - is thrown if an error occurs while accessing the underlying storage.
    • put

      public void put(int offset, byte[] bytes) throws IndexOutOfBoundsException, IOException
      Put the bytes provided into the buffer at the specified offset. The number of bytes stored is determined by the length of the bytes array.
      Parameters:
      offset - byte offset from start of buffer.
      bytes - the byte data to be stored.
      Throws:
      IndexOutOfBoundsException - if an invalid offset is provided or the end of buffer was encountered while storing the data.
      IOException - is thrown if an error occurs while accessing the underlying storage.
    • putByte

      public void putByte(int offset, byte b) throws IndexOutOfBoundsException, IOException
      Put the 8-bit byte value into the buffer at the specified offset.
      Parameters:
      offset - byte offset from start of buffer.
      b - the byte value to be stored.
      Throws:
      IndexOutOfBoundsException - if an invalid offset is provided.
      IOException - is thrown if an error occurs while accessing the underlying storage.
    • get

      public void get(int offset, byte[] data) throws IndexOutOfBoundsException, IOException
      Get the byte data located at the specified offset.
      Parameters:
      offset - byte offset from start of buffer.
      data - data buffer to be filled
      Throws:
      IndexOutOfBoundsException - is thrown if an invalid offset is specified or the end of the buffer was encountered while reading the data.
      IOException - is thrown if an error occurs while accessing the underlying storage.
    • delete

      public void delete() throws IOException
      Delete and release all underlying DataBuffers.
      Throws:
      IOException - is thrown if an error occurs while accessing the underlying storage.