Package org.h2.store
Class Data
- java.lang.Object
-
- org.h2.store.Data
-
public class Data extends java.lang.ObjectThis class represents a byte buffer that contains persistent data of a page.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateData(byte[] data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckCapacity(int plus)Check if there is still enough capacity in the buffer.static voidcopyString(java.io.Reader source, java.io.OutputStream target)Copy a String from a reader to an output stream.static Datacreate(int capacity)Create a new buffer.private voidexpand(int plus)voidfillAligned()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.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.private voidwriteStringWithoutLength(char[] chars, int len)
-
-
-
Method Detail
-
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 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
-
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(java.io.Reader source, java.io.OutputStream target) throws java.io.IOExceptionCopy a String from a reader to an output stream.- Parameters:
source- the readertarget- the output stream- Throws:
java.io.IOException- on failure
-
-