Package org.h2.store
Class Data
java.lang.Object
org.h2.store.Data
This class represents a byte buffer that contains persistent data of a page.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcheckCapacity(int plus) Check if there is still enough capacity in the buffer.static voidcopyString(Reader source, OutputStream target) Copy a String from a reader to an output stream.static Datacreate(int capacity) Create a new buffer.voidFill 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.intlength()Get the current write position of this buffer, which is the current length.voidread(byte[] buff, int off, int len) Copy a number of bytes to the given buffer from the current position.bytereadByte()Read one single byte.intreadInt()Read an integer at the current position.voidreset()Set the position to 0.voidsetPos(int pos) Set the current read / write position.voidwrite(byte[] buff, int off, int len) Append a number of bytes to this buffer.voidwriteInt(int x) Write an integer at the current position.
-
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
-
create
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 dataoff- the offset in the datalen- 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 bufferoff- the offset in the output bufferlen- 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
-
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
Copy a String from a reader to an output stream.- Parameters:
source- the readertarget- the output stream- Throws:
IOException- on failure
-