Package org.h2.value
Class Transfer
- java.lang.Object
-
- org.h2.value.Transfer
-
public final class Transfer extends java.lang.ObjectThe 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 intARRAYprivate static intBIGINTprivate static intBINARYprivate static intBLOBprivate static intBOOLEANprivate static intBUFFER_SIZEprivate static intCHARprivate static intCLOBprivate static intDATEprivate static intDECFLOATprivate static intDOUBLEprivate static intENUMprivate static intGEOMETRYprivate java.io.DataInputStreaminprivate static intINTEGERprivate static intINTERVALprivate static intJAVA_OBJECTprivate static intJSONprivate static intLOB_MAC_SALT_LENGTHprivate static intLOB_MAGICprivate byte[]lobMacSaltprivate static intNULLprivate static intNUMERICprivate java.io.DataOutputStreamoutprivate static intREALprivate static intROWprivate Sessionsessionprivate static intSMALLINTprivate java.net.Socketsocketprivate booleansslprivate static int[]TI_TO_VALUEprivate static intTIMEprivate static intTIME_TZprivate static intTIMESTAMPprivate static intTIMESTAMP_TZprivate static intTINYINTprivate static intUUIDprivate static int[]VALUE_TO_TIprivate static intVARBINARYprivate static intVARCHARprivate static intVARCHAR_IGNORECASEprivate intversion
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddType(int typeInformationType, int valueType)private byte[]calculateLobMac(long lobId)voidclose()Close the transfer object and the socket.voidflush()Write pending changes.java.net.SocketgetSocket()Get the socket.intgetVersion()voidinit()Initialize the transfer object.booleanisClosed()TransferopenNewConnection()Open a new connection to the same address and port as this one.private Value[]readArrayElements(int len, TypeInfo elementType)booleanreadBoolean()Read a boolean.bytereadByte()Read a byte.byte[]readBytes()Read a byte array.voidreadBytes(byte[] buff, int off, int len)Read a number of bytes.private doublereadDouble()Read a double.private floatreadFloat()Read a float.intreadInt()Read an int.longreadLong()Read a long.longreadRowCount()Read a row count.private shortreadShort()Read a short.java.lang.StringreadString()Read a string.TypeInforeadTypeInfo()Read a type information.private TypeInforeadTypeInfo19()private TypeInforeadTypeInfo20()private ExtTypeInforeadTypeInfoEnum()private ExtTypeInforeadTypeInfoGeometry()private ExtTypeInforeadTypeInfoRow()ValuereadValue(TypeInfo columnType)Read a value.voidsetSession(Session session)Set the session.voidsetSSL(boolean ssl)Enable or disable SSL.voidsetVersion(int version)voidverifyLobMac(byte[] hmac, long lobId)Verify the HMAC.TransferwriteBoolean(boolean x)Write a boolean.TransferwriteByte(byte x)Write a byte.private voidwriteBytePrecisionWithDefault(long precision)TransferwriteBytes(byte[] data)Write a byte array.TransferwriteBytes(byte[] buff, int off, int len)Write a number of bytes.private voidwriteByteScaleWithDefault(int scale)private TransferwriteDouble(double i)Write a double.private TransferwriteFloat(float i)Write a float.TransferwriteInt(int x)Write an int.TransferwriteLong(long x)Write a long.TransferwriteRowCount(long rowCount)Write a row count.private TransferwriteShort(short x)Write a short.TransferwriteString(java.lang.String s)Write a string.TransferwriteTypeInfo(TypeInfo type)Write value type, precision, and scale.private voidwriteTypeInfo19(TypeInfo type)private voidwriteTypeInfo20(TypeInfo type)private voidwriteTypeInfoEnum(TypeInfo type)private voidwriteTypeInfoGeometry(TypeInfo type)private voidwriteTypeInfoRow(TypeInfo type)voidwriteValue(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.IOExceptionInitialize 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.IOExceptionWrite 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead a double.- Returns:
- the value
- Throws:
java.io.IOException- on failure
-
readFloat
private float readFloat() throws java.io.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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)
-
-