Package org.h2.store

Class Data

java.lang.Object
org.h2.store.Data

public class Data extends Object
This class represents a byte buffer that contains persistent data of a page.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    The data itself.
    private int
    The current write or read position.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Data(byte[] data)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    checkCapacity(int plus)
    Check if there is still enough capacity in the buffer.
    static void
    copyString(Reader source, OutputStream target)
    Copy a String from a reader to an output stream.
    static Data
    create(int capacity)
    Create a new buffer.
    private void
    expand(int plus)
     
    void
    Fill up the buffer with empty space and an (initially empty) checksum until the size is a multiple of Constants.FILE_BLOCK_SIZE.
    byte[]
    Get the byte array used for this page.
    int
    Get the current write position of this buffer, which is the current length.
    void
    read(byte[] buff, int off, int len)
    Copy a number of bytes to the given buffer from the current position.
    byte
    Read one single byte.
    int
    Read an integer at the current position.
    void
    Set the position to 0.
    void
    setPos(int pos)
    Set the current read / write position.
    void
    write(byte[] buff, int off, int len)
    Append a number of bytes to this buffer.
    void
    writeInt(int x)
    Write an integer at the current position.
    private void
    writeStringWithoutLength(char[] chars, int len)
     

    Methods inherited from class java.lang.Object

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

    • data

      private byte[] data
      The data itself.
    • pos

      private int pos
      The current write or read position.
  • Constructor Details

    • Data

      private Data(byte[] data)
  • Method Details

    • writeInt

      public void writeInt(int x)
      Write an integer at the current position. The current position is incremented.
      Parameters:
      x - the value
    • readInt

      public int readInt()
      Read an integer at the current position. The current position is incremented.
      Returns:
      the value
    • writeStringWithoutLength

      private void writeStringWithoutLength(char[] chars, int len)
    • create

      public static Data create(int capacity)
      Create a new buffer.
      Parameters:
      capacity - the initial capacity of the buffer
      Returns:
      the buffer
    • length

      public int length()
      Get the current write position of this buffer, which is the current length.
      Returns:
      the length
    • getBytes

      public byte[] getBytes()
      Get the byte array used for this page.
      Returns:
      the byte array
    • reset

      public void reset()
      Set the position to 0.
    • write

      public void write(byte[] buff, int off, int len)
      Append a number of bytes to this buffer.
      Parameters:
      buff - the data
      off - the offset in the data
      len - the length in bytes
    • read

      public void read(byte[] buff, int off, int len)
      Copy a number of bytes to the given buffer from the current position. The current position is incremented accordingly.
      Parameters:
      buff - the output buffer
      off - the offset in the output buffer
      len - the number of bytes to copy
    • setPos

      public void setPos(int pos)
      Set the current read / write position.
      Parameters:
      pos - the new position
    • readByte

      public byte readByte()
      Read one single byte.
      Returns:
      the value
    • checkCapacity

      public void checkCapacity(int plus)
      Check if there is still enough capacity in the buffer. This method extends the buffer if required.
      Parameters:
      plus - the number of additional bytes required
    • expand

      private void expand(int plus)
    • fillAligned

      public void fillAligned()
      Fill up the buffer with empty space and an (initially empty) checksum until the size is a multiple of Constants.FILE_BLOCK_SIZE.
    • copyString

      public static void copyString(Reader source, OutputStream target) throws IOException
      Copy a String from a reader to an output stream.
      Parameters:
      source - the reader
      target - the output stream
      Throws:
      IOException - on failure