org.h2.store
Class Data

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

public class Data
extends DataPage

A data page is a byte buffer that contains persistent data of a page.


Field Summary
 
Fields inherited from class org.h2.store.DataPage
data, handler, LENGTH_FILLER, LENGTH_INT, LENGTH_LONG, pos
 
Method Summary
static Data create(DataHandler handler, byte[] buff)
          Create a new data page using the given data for the given handler.
static Data create(DataHandler handler, int capacity)
          Create a new data page for the given handler.
 void fill(int len)
          Increase the size to the given length.
 byte[] getBytes()
          Get the byte array used for this page.
 int getStringLen(java.lang.String s)
          Get the length of a String value.
 int getValueLen(Value v)
          Calculate the number of bytes required to encode the given value.
 int getVarLongLen(long x)
          The number of bytes required for a variable size long.
 int length()
          Get the current write position of this data page, 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.
 int readByte()
          Read one single byte.
 int readInt()
          Read an integer at the current position.
 long readLong()
          Read a long value.
 int 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 data page.
 void writeByte(byte x)
          Append one single byte.
 void writeDataPageNoSize(Data page)
          Append the contents of the given data page to this page.
 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 value.
 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 org.h2.store.DataPage
check, checkCapacity, fillAligned, readDataPageNoSize, updateChecksum, writeDataPageNoSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setInt

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

Overrides:
setInt in class DataPage
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.

Overrides:
writeInt in class DataPage
Parameters:
x - the value

readInt

public int readInt()
Read an integer at the current position. The current position is incremented.

Overrides:
readInt in class DataPage
Returns:
the value

getStringLen

public int getStringLen(java.lang.String s)
Get the length of a String value.

Overrides:
getStringLen in class DataPage
Parameters:
s - the value
Returns:
the length

readString

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

Overrides:
readString in class DataPage
Returns:
the value

writeString

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

Overrides:
writeString in class DataPage
Parameters:
s - the value

fill

public void fill(int len)
Increase the size to the given length. The current position is set to the given value.

Overrides:
fill in class DataPage
Parameters:
len - the new length

create

public static Data create(DataHandler handler,
                          int capacity)
Create a new data page 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 data page

create

public static Data create(DataHandler handler,
                          byte[] buff)
Create a new data page 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 data page

length

public int length()
Get the current write position of this data page, which is the current length.

Overrides:
length in class DataPage
Returns:
the length

getBytes

public byte[] getBytes()
Get the byte array used for this page.

Overrides:
getBytes in class DataPage
Returns:
the byte array

reset

public void reset()
Set the position to 0.

Overrides:
reset in class DataPage

writeDataPageNoSize

public void writeDataPageNoSize(Data page)
Append the contents of the given data page to this page. The filler is not appended.

Parameters:
page - the page that will be appended

write

public void write(byte[] buff,
                  int off,
                  int len)
Append a number of bytes to this data page.

Overrides:
write in class DataPage
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.

Overrides:
read in class DataPage
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.

Overrides:
writeByte in class DataPage
Parameters:
x - the value

readByte

public int readByte()
Read one single byte.

Overrides:
readByte in class DataPage
Returns:
the value

readLong

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

Overrides:
readLong in class DataPage
Returns:
the long value

writeLong

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

Overrides:
writeLong in class DataPage
Parameters:
x - the value

writeValue

public void writeValue(Value v)
                throws java.sql.SQLException
Append a value.

Overrides:
writeValue in class DataPage
Parameters:
v - the value
Throws:
java.sql.SQLException

readValue

public Value readValue()
                throws java.sql.SQLException
Read a value.

Overrides:
readValue in class DataPage
Returns:
the value
Throws:
java.sql.SQLException

getValueLen

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

Overrides:
getValueLen in class DataPage
Parameters:
v - the value
Returns:
the number of bytes required to store this value
Throws:
java.sql.SQLException

setPos

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

Overrides:
setPos in class DataPage
Parameters:
pos - the new position

writeShortInt

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

Overrides:
writeShortInt in class DataPage
Parameters:
x - the value

readShortInt

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

Overrides:
readShortInt in class DataPage
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 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