Package org.h2.value
Class Transfer
- java.lang.Object
-
- org.h2.value.Transfer
-
public final class Transfer extends java.lang.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.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
ARRAY
private static int
BIGINT
private static int
BINARY
private static int
BLOB
private static int
BOOLEAN
private static int
BUFFER_SIZE
private static int
CHAR
private static int
CLOB
private static int
DATE
private static int
DECFLOAT
private static int
DOUBLE
private static int
ENUM
private static int
GEOMETRY
private java.io.DataInputStream
in
private static int
INTEGER
private static int
INTERVAL
private static int
JAVA_OBJECT
private static int
JSON
private static int
LOB_MAC_SALT_LENGTH
private static int
LOB_MAGIC
private byte[]
lobMacSalt
private static int
NULL
private static int
NUMERIC
private java.io.DataOutputStream
out
private static int
REAL
private static int
ROW
private Session
session
private static int
SMALLINT
private java.net.Socket
socket
private boolean
ssl
private static int[]
TI_TO_VALUE
private static int
TIME
private static int
TIME_TZ
private static int
TIMESTAMP
private static int
TIMESTAMP_TZ
private static int
TINYINT
private static int
UUID
private static int[]
VALUE_TO_TI
private static int
VARBINARY
private static int
VARCHAR
private static int
VARCHAR_IGNORECASE
private int
version
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
addType(int typeInformationType, int valueType)
private byte[]
calculateLobMac(long lobId)
void
close()
Close the transfer object and the socket.void
flush()
Write pending changes.java.net.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.private Value[]
readArrayElements(int len, TypeInfo elementType)
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.private double
readDouble()
Read a double.private float
readFloat()
Read a float.int
readInt()
Read an int.long
readLong()
Read a long.long
readRowCount()
Read a row count.private short
readShort()
Read a short.java.lang.String
readString()
Read a string.TypeInfo
readTypeInfo()
Read a type information.private TypeInfo
readTypeInfo19()
private TypeInfo
readTypeInfo20()
private ExtTypeInfo
readTypeInfoEnum()
private ExtTypeInfo
readTypeInfoGeometry()
private ExtTypeInfo
readTypeInfoRow()
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.private void
writeBytePrecisionWithDefault(long precision)
Transfer
writeBytes(byte[] data)
Write a byte array.Transfer
writeBytes(byte[] buff, int off, int len)
Write a number of bytes.private void
writeByteScaleWithDefault(int scale)
private Transfer
writeDouble(double i)
Write a double.private Transfer
writeFloat(float i)
Write a float.Transfer
writeInt(int x)
Write an int.Transfer
writeLong(long x)
Write a long.Transfer
writeRowCount(long rowCount)
Write a row count.private Transfer
writeShort(short x)
Write a short.Transfer
writeString(java.lang.String s)
Write a string.Transfer
writeTypeInfo(TypeInfo type)
Write value type, precision, and scale.private void
writeTypeInfo19(TypeInfo type)
private void
writeTypeInfo20(TypeInfo type)
private void
writeTypeInfoEnum(TypeInfo type)
private void
writeTypeInfoGeometry(TypeInfo type)
private void
writeTypeInfoRow(TypeInfo type)
void
writeValue(Value v)
Write a value.
-
-
-
Field Detail
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
LOB_MAGIC
private static final int LOB_MAGIC
- See Also:
- Constant Field Values
-
LOB_MAC_SALT_LENGTH
private static final int LOB_MAC_SALT_LENGTH
- See Also:
- Constant Field Values
-
NULL
private static final int NULL
- See Also:
- Constant Field Values
-
BOOLEAN
private static final int BOOLEAN
- See Also:
- Constant Field Values
-
TINYINT
private static final int TINYINT
- See Also:
- Constant Field Values
-
SMALLINT
private static final int SMALLINT
- See Also:
- Constant Field Values
-
INTEGER
private static final int INTEGER
- See Also:
- Constant Field Values
-
BIGINT
private static final int BIGINT
- See Also:
- Constant Field Values
-
NUMERIC
private static final int NUMERIC
- See Also:
- Constant Field Values
-
DOUBLE
private static final int DOUBLE
- See Also:
- Constant Field Values
-
REAL
private static final int REAL
- See Also:
- Constant Field Values
-
TIME
private static final int TIME
- See Also:
- Constant Field Values
-
DATE
private static final int DATE
- See Also:
- Constant Field Values
-
TIMESTAMP
private static final int TIMESTAMP
- See Also:
- Constant Field Values
-
VARBINARY
private static final int VARBINARY
- See Also:
- Constant Field Values
-
VARCHAR
private static final int VARCHAR
- See Also:
- Constant Field Values
-
VARCHAR_IGNORECASE
private static final int VARCHAR_IGNORECASE
- See Also:
- Constant Field Values
-
BLOB
private static final int BLOB
- See Also:
- Constant Field Values
-
CLOB
private static final int CLOB
- See Also:
- Constant Field Values
-
ARRAY
private static final int ARRAY
- See Also:
- Constant Field Values
-
JAVA_OBJECT
private static final int JAVA_OBJECT
- See Also:
- Constant Field Values
-
UUID
private static final int UUID
- See Also:
- Constant Field Values
-
CHAR
private static final int CHAR
- See Also:
- Constant Field Values
-
GEOMETRY
private static final int GEOMETRY
- See Also:
- Constant Field Values
-
TIMESTAMP_TZ
private static final int TIMESTAMP_TZ
- See Also:
- Constant Field Values
-
ENUM
private static final int ENUM
- See Also:
- Constant Field Values
-
INTERVAL
private static final int INTERVAL
- See Also:
- Constant Field Values
-
ROW
private static final int ROW
- See Also:
- Constant Field Values
-
JSON
private static final int JSON
- See Also:
- Constant Field Values
-
TIME_TZ
private static final int TIME_TZ
- See Also:
- Constant Field Values
-
BINARY
private static final int BINARY
- See Also:
- Constant Field Values
-
DECFLOAT
private static final int DECFLOAT
- See Also:
- Constant Field Values
-
VALUE_TO_TI
private static final int[] VALUE_TO_TI
-
TI_TO_VALUE
private static final int[] TI_TO_VALUE
-
socket
private java.net.Socket socket
-
in
private java.io.DataInputStream in
-
out
private java.io.DataOutputStream out
-
session
private Session session
-
ssl
private boolean ssl
-
version
private int version
-
lobMacSalt
private byte[] lobMacSalt
-
-
Constructor Detail
-
Transfer
public Transfer(Session session, java.net.Socket s)
Create a new transfer object for the specified session.- Parameters:
session
- the sessions
- the socket
-
-
Method Detail
-
addType
private static void addType(int typeInformationType, int valueType)
-
init
public void init() throws java.io.IOException
Initialize the transfer object. This method will try to open an input and output stream.- Throws:
java.io.IOException
- on failure
-
flush
public void flush() throws java.io.IOException
Write pending changes.- Throws:
java.io.IOException
- on failure
-
writeBoolean
public Transfer writeBoolean(boolean x) throws java.io.IOException
Write a boolean.- Parameters:
x
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readBoolean
public boolean readBoolean() throws java.io.IOException
Read a boolean.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeByte
public Transfer writeByte(byte x) throws java.io.IOException
Write a byte.- Parameters:
x
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readByte
public byte readByte() throws java.io.IOException
Read a byte.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeShort
private Transfer writeShort(short x) throws java.io.IOException
Write a short.- Parameters:
x
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readShort
private short readShort() throws java.io.IOException
Read a short.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeInt
public Transfer writeInt(int x) throws java.io.IOException
Write an int.- Parameters:
x
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readInt
public int readInt() throws java.io.IOException
Read an int.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeLong
public Transfer writeLong(long x) throws java.io.IOException
Write a long.- Parameters:
x
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readLong
public long readLong() throws java.io.IOException
Read a long.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeDouble
private Transfer writeDouble(double i) throws java.io.IOException
Write a double.- Parameters:
i
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
writeFloat
private Transfer writeFloat(float i) throws java.io.IOException
Write a float.- Parameters:
i
- the value- Returns:
- itself
- Throws:
java.io.IOException
-
readDouble
private double readDouble() throws java.io.IOException
Read a double.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
readFloat
private float readFloat() throws java.io.IOException
Read a float.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeString
public Transfer writeString(java.lang.String s) throws java.io.IOException
Write a string. The maximum string length is Integer.MAX_VALUE.- Parameters:
s
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readString
public java.lang.String readString() throws java.io.IOException
Read a string.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
writeBytes
public Transfer writeBytes(byte[] data) throws java.io.IOException
Write a byte array.- Parameters:
data
- the value- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
writeBytes
public Transfer writeBytes(byte[] buff, int off, int len) throws java.io.IOException
Write a number of bytes.- Parameters:
buff
- the valueoff
- the offsetlen
- the length- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
readBytes
public byte[] readBytes() throws java.io.IOException
Read a byte array.- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
readBytes
public void readBytes(byte[] buff, int off, int len) throws java.io.IOException
Read a number of bytes.- Parameters:
buff
- the target bufferoff
- the offsetlen
- the number of bytes to read- Throws:
java.io.IOException
- on failure
-
close
public void close()
Close the transfer object and the socket.
-
writeTypeInfo
public Transfer writeTypeInfo(TypeInfo type) throws java.io.IOException
Write value type, precision, and scale.- Parameters:
type
- data type information- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
writeTypeInfo20
private void writeTypeInfo20(TypeInfo type) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBytePrecisionWithDefault
private void writeBytePrecisionWithDefault(long precision) throws java.io.IOException
- Throws:
java.io.IOException
-
writeByteScaleWithDefault
private void writeByteScaleWithDefault(int scale) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTypeInfoEnum
private void writeTypeInfoEnum(TypeInfo type) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTypeInfoGeometry
private void writeTypeInfoGeometry(TypeInfo type) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTypeInfoRow
private void writeTypeInfoRow(TypeInfo type) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTypeInfo19
private void writeTypeInfo19(TypeInfo type) throws java.io.IOException
- Throws:
java.io.IOException
-
readTypeInfo
public TypeInfo readTypeInfo() throws java.io.IOException
Read a type information.- Returns:
- the type information
- Throws:
java.io.IOException
- on failure
-
readTypeInfo20
private TypeInfo readTypeInfo20() throws java.io.IOException
- Throws:
java.io.IOException
-
readTypeInfoEnum
private ExtTypeInfo readTypeInfoEnum() throws java.io.IOException
- Throws:
java.io.IOException
-
readTypeInfoGeometry
private ExtTypeInfo readTypeInfoGeometry() throws java.io.IOException
- Throws:
java.io.IOException
-
readTypeInfoRow
private ExtTypeInfo readTypeInfoRow() throws java.io.IOException
- Throws:
java.io.IOException
-
readTypeInfo19
private TypeInfo readTypeInfo19() throws java.io.IOException
- Throws:
java.io.IOException
-
writeValue
public void writeValue(Value v) throws java.io.IOException
Write a value.- Parameters:
v
- the value- Throws:
java.io.IOException
- on failure
-
readValue
public Value readValue(TypeInfo columnType) throws java.io.IOException
Read a value.- Parameters:
columnType
- the data type of value, ornull
- Returns:
- the value
- Throws:
java.io.IOException
- on failure
-
readArrayElements
private Value[] readArrayElements(int len, TypeInfo elementType) throws java.io.IOException
- Throws:
java.io.IOException
-
readRowCount
public long readRowCount() throws java.io.IOException
Read a row count.- Returns:
- the row count
- Throws:
java.io.IOException
- on failure
-
writeRowCount
public Transfer writeRowCount(long rowCount) throws java.io.IOException
Write a row count.- Parameters:
rowCount
- the row count- Returns:
- itself
- Throws:
java.io.IOException
- on failure
-
getSocket
public java.net.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 java.io.IOException
Open a new connection to the same address and port as this one.- Returns:
- the new transfer object
- Throws:
java.io.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 codelobId
- the lobId- Throws:
DbException
- if the HMAC does not match
-
calculateLobMac
private byte[] calculateLobMac(long lobId)
-
-