org.h2.store
Class Data

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

public class Data
extends java.lang.Object

This class represents a byte buffer that contains persistent data of a page.


Field Summary
static int LENGTH_INT
          The length of an integer value.
 
Method Summary
 void checkCapacity(int plus)
          Check if there is still enough capacity in the buffer.
static void copyString(java.io.Reader source, java.io.OutputStream target)
          Copy a String from a reader to an output stream.
static Data create(DataHandler handler, byte[] buff)
          Create a new buffer using the given data for the given handler.
static Data create(DataHandler handler, int capacity)
          Create a new buffer for the given handler.
 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.
 byte[] getBytes()
          Get the byte array used for this page.
 DataHandler getHandler()
           
static int getStringLen(java.lang.String s)
          Get the length of a String.
 int getValueLen(Value v)
          Calculate the number of bytes required to encode the given value.
static int getValueLen(Value v, DataHandler handler)
          Calculate the number of bytes required to encode the given value.
static int getVarLongLen(long x)
          The number of bytes required for a variable size long.
 int length()
          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 readByte()
          Read one single byte.
 int readInt()
          Read an integer at the current position.
 long readLong()
          Read a long value.
 short readShortInt()
          Read an short integer at the current position.
 java.lang.String readString()
          Read a String value.
 Value readValue()
          Read a value.
 int readVarInt()
          Read a variable size int.
 long readVarLong()
          Read a variable size long.
 void reset()
          Set the position to 0.
 void setInt(int pos, int x)
          Update an integer at the given position.
 void setPos(int pos)
          Set the current read / write position.
 void truncate(int size)
          Shrink the array to this size.
 void write(byte[] buff, int off, int len)
          Append a number of bytes to this buffer.
 void writeByte(byte x)
          Append one single byte.
 void writeInt(int x)
          Write an integer at the current position.
 void writeLong(long x)
          Append a long value.
 void writeShortInt(int x)
          Write a short integer at the current position.
 void writeString(java.lang.String s)
          Write a String.
 void writeValue(Value v)
          Append a value.
 void writeVarInt(int x)
          Write a variable size int.
 void writeVarLong(long x)
          Write a variable size long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LENGTH_INT

public static final int LENGTH_INT
The length of an integer value.

See Also:
Constant Field Values
Method Detail

setInt

public void setInt(int pos,
                   int x)
Update an integer at the given position. The current position is not change.

Parameters:
pos - the position
x - the value

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

getStringLen

public static int getStringLen(java.lang.String s)
Get the length of a String. This includes the bytes required to encode the length.

Parameters:
s - the string
Returns:
the number of bytes required

readString

public java.lang.String readString()
Read a String value. The current position is incremented.

Returns:
the value

writeString

public void writeString(java.lang.String s)
Write a String. The current position is incremented.

Parameters:
s - the value

create

public static Data create(DataHandler handler,
                          int capacity)
Create a new buffer for the given handler. The handler will decide what type of buffer is created.

Parameters:
handler - the data handler
capacity - the initial capacity of the buffer
Returns:
the buffer

create

public static Data create(DataHandler handler,
                          byte[] buff)
Create a new buffer using the given data for the given handler. The handler will decide what type of buffer is created.

Parameters:
handler - the data handler
buff - the data
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

writeByte

public void writeByte(byte x)
Append one single byte.

Parameters:
x - the value

readByte

public byte readByte()
Read one single byte.

Returns:
the value

readLong

public long readLong()
Read a long value. This method reads two int values and combines them.

Returns:
the long value

writeLong

public void writeLong(long x)
Append a long value. This method writes two int values.

Parameters:
x - the value

writeValue

public void writeValue(Value v)
Append a value.

Parameters:
v - the value

readValue

public Value readValue()
Read a value.

Returns:
the value

getValueLen

public int getValueLen(Value v)
Calculate the number of bytes required to encode the given value.

Parameters:
v - the value
Returns:
the number of bytes required to store this value

getValueLen

public static int getValueLen(Value v,
                              DataHandler handler)
Calculate the number of bytes required to encode the given value.

Parameters:
v - the value
handler - the data handler for lobs
Returns:
the number of bytes required to store this value

setPos

public void setPos(int pos)
Set the current read / write position.

Parameters:
pos - the new position

writeShortInt

public void writeShortInt(int x)
Write a short integer at the current position. The current position is incremented.

Parameters:
x - the value

readShortInt

public short readShortInt()
Read an short integer at the current position. The current position is incremented.

Returns:
the value

truncate

public void truncate(int size)
Shrink the array to this size.

Parameters:
size - the new size

writeVarInt

public void writeVarInt(int x)
Write a variable size int.

Parameters:
x - the value

readVarInt

public int readVarInt()
Read a variable size int.

Returns:
the value

getVarLongLen

public static int getVarLongLen(long x)
The number of bytes required for a variable size long.

Parameters:
x - the value
Returns:
the len

writeVarLong

public void writeVarLong(long x)
Write a variable size long.

Parameters:
x - the value

readVarLong

public long readVarLong()
Read a variable size long.

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

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(java.io.Reader source,
                              java.io.OutputStream target)
                       throws java.io.IOException
Copy a String from a reader to an output stream.

Parameters:
source - the reader
target - the output stream
Throws:
java.io.IOException

getHandler

public DataHandler getHandler()