Class Serialization


  • public class Serialization
    extends Object
    • Method Detail

      • readList

        public static byte[][] readList​(InputStream input,
                                        int listWidth,
                                        int elemWidth)
                                 throws SerializationException
        Read a variable length vector of variable sized elements as described by RFC5246 section 4.3. The vector is prefixed by its total length, in bytes and in big endian format, so is each element contained in the vector.
        Parameters:
        listWidth - the width of the vector's length field, in bytes.
        elemWidth - the width of each element's length field, in bytes.
        Throws:
        SerializationException - if EOF is encountered.
      • readVariableBytes

        public static byte[] readVariableBytes​(InputStream input,
                                               int width)
                                        throws SerializationException
        Read a length-prefixed sequence of bytes. The length must be encoded in big endian format.
        Parameters:
        width - the width of the length prefix, in bytes.
        Throws:
        SerializationException - if EOF is encountered, or if width is negative or greater than 4
      • readFixedBytes

        public static byte[] readFixedBytes​(InputStream input,
                                            int length)
                                     throws SerializationException
        Read a fixed number of bytes from the input stream.
        Parameters:
        length - the number of bytes to read.
        Throws:
        SerializationException - if EOF is encountered.
      • readNumber

        public static int readNumber​(InputStream input,
                                     int width)
                              throws SerializationException
        Read a number in big endian format from the input stream. This methods only supports a width of up to 4 bytes.
        Parameters:
        width - the width of the number, in bytes.
        Throws:
        SerializationException - if EOF is encountered, or if width is negative or greater than 4
      • writeVariableBytes

        public static void writeVariableBytes​(OutputStream output,
                                              byte[] data,
                                              int width)
                                       throws SerializationException
        Write length prefixed sequence of bytes to the ouput stream. The length prefix is encoded in big endian order.
        Parameters:
        data - the data to be written.
        width - the width of the length prefix, in bytes.
        Throws:
        SerializationException - if the length of data is too large to fit in width bytes or width is negative.
      • writeNumber

        public static void writeNumber​(OutputStream output,
                                       long value,
                                       int width)
                                throws SerializationException
        Write a number to the output stream. The number is encoded in big endian order.
        Parameters:
        value - the value to be written.
        width - the width of the encoded number, in bytes
        Throws:
        SerializationException - if the number is too large to fit in width bytes or width is negative.