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.

## 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.
`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.
`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.
`void`
`reset()`
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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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

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

### 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