Package org.h2.value

# Class Transfer

java.lang.Object
org.h2.value.Transfer

public final class Transfer extends Object
The transfer class is used to send and receive Value objects. It is used on both the client side, and on the server side.

## Constructor Summary

Constructors
Constructor
Description
`Transfer(Session session, Socket s)`
Create a new transfer object for the specified session.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close the transfer object and the socket.
`void`
`flush()`
Write pending changes.
`Socket`
`getSocket()`
Get the socket.
`int`
`getVersion()`
`void`
`init()`
Initialize the transfer object.
`boolean`
`isClosed()`
`Transfer`
`openNewConnection()`
Open a new connection to the same address and port as this one.
`boolean`
`readBoolean()`
Read a boolean.
`byte`
`readByte()`
Read a byte.
`byte[]`
`readBytes()`
Read a byte array.
`void`
`readBytes(byte[] buff, int off, int len)`
Read a number of bytes.
`int`
`readInt()`
Read an int.
`long`
`readLong()`
Read a long.
`long`
`readRowCount()`
Read a row count.
`String`
`readString()`
Read a string.
`TypeInfo`
`readTypeInfo()`
Read a type information.
`Value`
`readValue(TypeInfo columnType)`
Read a value.
`void`
`setSession(Session session)`
Set the session.
`void`
`setSSL(boolean ssl)`
Enable or disable SSL.
`void`
`setVersion(int version)`
`void`
`verifyLobMac(byte[] hmac, long lobId)`
Verify the HMAC.
`Transfer`
`writeBoolean(boolean x)`
Write a boolean.
`Transfer`
`writeByte(byte x)`
Write a byte.
`Transfer`
`writeBytes(byte[] data)`
Write a byte array.
`Transfer`
`writeBytes(byte[] buff, int off, int len)`
Write a number of bytes.
`Transfer`
`writeInt(int x)`
Write an int.
`Transfer`
`writeLong(long x)`
Write a long.
`Transfer`
`writeRowCount(long rowCount)`
Write a row count.
`Transfer`
`writeString(String s)`
Write a string.
`Transfer`
`writeTypeInfo(TypeInfo type)`
Write value type, precision, and scale.
`void`
`writeValue(Value v)`
Write a value.

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

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

## Constructor Details

### Transfer

public Transfer(Session session, Socket s)
Create a new transfer object for the specified session.

Parameters:
  `session` - the session
  `s` - the socket

## Method Details

### init

public void init() throws IOException
Initialize the transfer object. This method will try to open an input and output stream.

Throws:
  `IOException` - on failure

### flush

public void flush() throws IOException
Write pending changes.

Throws:
  `IOException` - on failure

### writeBoolean

public Transfer writeBoolean(boolean x) throws IOException
Write a boolean.

Parameters:
  `x` - the value
Returns:
  itself
Throws:
  `IOException` - on failure

### readBoolean

public boolean readBoolean() throws IOException
Read a boolean.

Returns:
  the value
Throws:
  `IOException` - on failure

### writeByte

public Transfer writeByte(byte x) throws IOException
Write a byte.

Parameters:
  `x` - the value
Returns:
  itself
Throws:
  `IOException` - on failure

### readByte

public byte readByte() throws IOException
Read a byte.

Returns:
  the value
Throws:
  `IOException` - on failure

### writeInt

public Transfer writeInt(int x) throws IOException
Write an int.

Parameters:
  `x` - the value
Returns:
  itself
Throws:
  `IOException` - on failure

### readInt

public int readInt() throws IOException
Read an int.

Returns:
  the value
Throws:
  `IOException` - on failure

### writeLong

public Transfer writeLong(long x) throws IOException
Write a long.

Parameters:
  `x` - the value
Returns:
  itself
Throws:
  `IOException` - on failure

### readLong

public long readLong() throws IOException
Read a long.

Returns:
  the value
Throws:
  `IOException` - on failure

### writeString

public Transfer writeString(String s) throws IOException
Write a string. The maximum string length is Integer.MAX_VALUE.

Parameters:
  `s` - the value
Returns:
  itself
Throws:
  `IOException` - on failure

### readString

public String readString() throws IOException
Read a string.

Returns:
  the value
Throws:
  `IOException` - on failure

### writeBytes

public Transfer writeBytes(byte[] data) throws IOException
Write a byte array.

Parameters:
  `data` - the value
Returns:
  itself
Throws:
  `IOException` - on failure

### writeBytes

public Transfer writeBytes(byte[] buff, int off, int len) throws IOException
Write a number of bytes.

Parameters:
  `buff` - the value
  `off` - the offset
  `len` - the length
Returns:
  itself
Throws:
  `IOException` - on failure

### readBytes

public byte[] readBytes() throws IOException
Read a byte array.

Returns:
  the value
Throws:
  `IOException` - on failure

### readBytes

public void readBytes(byte[] buff, int off, int len) throws IOException
Read a number of bytes.

Parameters:
  `buff` - the target buffer
  `off` - the offset
  `len` - the number of bytes to read
Throws:
  `IOException` - on failure

### close

public void close()
Close the transfer object and the socket.

### writeTypeInfo

public Transfer writeTypeInfo(TypeInfo type) throws IOException
Write value type, precision, and scale.

Parameters:
  `type` - data type information
Returns:
  itself
Throws:
  `IOException` - on failure

### readTypeInfo

public TypeInfo readTypeInfo() throws IOException
Read a type information.

Returns:
  the type information
Throws:
  `IOException` - on failure

### writeValue

public void writeValue(Value v) throws IOException
Write a value.

Parameters:
  `v` - the value
Throws:
  `IOException` - on failure

### readValue

public Value readValue(TypeInfo columnType) throws IOException
Read a value.

Parameters:
  `columnType` - the data type of value, or `null`
Returns:
  the value
Throws:
  `IOException` - on failure

### readRowCount

public long readRowCount() throws IOException
Read a row count.

Returns:
  the row count
Throws:
  `IOException` - on failure

### writeRowCount

public Transfer writeRowCount(long rowCount) throws IOException
Write a row count.

Parameters:
  `rowCount` - the row count
Returns:
  itself
Throws:
  `IOException` - on failure

### getSocket

public Socket getSocket()
Get the socket.

Returns:
  the socket

### setSession

public void setSession(Session session)
Set the session.

Parameters:
  `session` - the session

### setSSL

public void setSSL(boolean ssl)
Enable or disable SSL.

Parameters:
  `ssl` - the new value

### openNewConnection

public Transfer openNewConnection() throws IOException
Open a new connection to the same address and port as this one.

Returns:
  the new transfer object
Throws:
  `IOException` - on failure

### setVersion

public void setVersion(int version)

### getVersion

public int getVersion()

### isClosed

public boolean isClosed()

### verifyLobMac

public void verifyLobMac(byte[] hmac, long lobId)
Verify the HMAC.

Parameters:
  `hmac` - the message authentication code
  `lobId` - the lobId
Throws:
  `DbException` - if the HMAC does not match