Package org.h2.value

Class 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.
    • Constructor Detail

      • Transfer

        public Transfer​(Session session,
                        java.net.Socket s)
        Create a new transfer object for the specified session.
        Parameters:
        session - the session
        s - 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 value
        off - the offset
        len - 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 buffer
        off - the offset
        len - 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, or null
        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 code
        lobId - the lobId
        Throws:
        DbException - if the HMAC does not match
      • calculateLobMac

        private byte[] calculateLobMac​(long lobId)