Class FastSerialize

    • Method Detail

      • readString

        public static String readString​(DataInput inStream)
                                 throws IOException
        Read a string value from the specified data input stream. Supports strings greater than 65535 characters in length.
        Parameters:
        inStream - the input stream to read from.
        Returns:
        the string value, or null if a null string value was stored in the stream.
        Throws:
        IOException - if an I/O error occurs.
      • writeString

        public static void writeString​(String value,
                                       DataOutput outStream)
                                throws IOException
        Write a string value to the specified data output stream. Supports strings greater than 65535 characters in length.
        Parameters:
        value - the string value to write. May be null.
        outStream - the output stream to write to.
        Throws:
        IOException - if an I/O error occurs.
      • standardSerialize

        public static byte[] standardSerialize​(Object toSerialise)
                                        throws IOException
        Serialise an object to a byte array using the standard Java serialisation approach.
        Parameters:
        toSerialise - the object to serialise. May be null.
        Returns:
        the serialised form of the object, or null if the input toSerialise argument is null.
        Throws:
        IOException - if an I/O error occurs.
      • standardDeserialize

        public static Object standardDeserialize​(byte[] byteArray,
                                                 ClassLoader classLoader)
                                          throws IOException
        Deserialise an object from a byte array using the standard Java deserialisation approach.

        If the input byteArray argument is not null then this method is equivalent to standardDeserialize(byteArray, 0, byteArray.length, classLoader).

        Parameters:
        byteArray - the serialised data to deserialise. May be null.
        classLoader - the class loader to be used during deserialisation.
        Returns:
        the deserialised object, or null if the input byteArray argument is null.
        Throws:
        IOException - if an I/O error occurs.
      • standardDeserialize

        public static Object standardDeserialize​(byte[] byteArray,
                                                 int offset,
                                                 int length)
                                          throws IOException
        Deserialise an object from a byte array using the standard Java serialisation approach.

        This method is equivalent to standardDeserialize(byteArray, offset, length, Thread.currentThread().getContextClassLoader()).

        Parameters:
        byteArray - the serialised data to deserialise. May be null.
        offset - the offset within byteArray of the data to start deserialisation from.
        length - the length of data within byteArray to be read.
        Returns:
        the deserialised object, or null if the input byteArray argument is null.
        Throws:
        IOException - if an I/O error occurs.
      • standardDeserialize

        public static Object standardDeserialize​(byte[] byteArray,
                                                 int offset,
                                                 int length,
                                                 ClassLoader classLoader)
                                          throws IOException
        Deserialise an object from a byte array using the standard Java serialisation approach.
        Parameters:
        byteArray - the serialised data to deserialise. May be null.
        offset - the offset within byteArray of the data to start deserialisation from.
        length - the length of data within byteArray to be read.
        classLoader - the class loader to be used during deserialisation.
        Returns:
        the deserialised object, or null if the input byteArray argument is null.
        Throws:
        IOException - if an I/O error occurs.
      • fastSerialize

        public static byte[] fastSerialize​(Object obj)
                                    throws IOException
        Serialise an object to a byte array using the FastSerializable approach where possible. The resulting data should be deserialised using fastDeserialize(byte[]).

        This method uses toStream(Object, DataOutput) to do the actual serialisation.

        Parameters:
        obj - the object to serialise. May be null.
        Returns:
        a byte array containing the serialised data.
        Throws:
        IOException - if an I/O error occurs.
      • fastDeserialize

        public static Object fastDeserialize​(byte[] data,
                                             int offset,
                                             int length,
                                             ClassLoader classLoader)
                                      throws IOException
        Deserialise an object from a byte array using the FastSerializable approach where possible.

        This method uses fromStream(DataInput, ClassLoader) to do the actual deserialisation.

        Parameters:
        data - the serialised data (from fastSerialize(Object)) to deserialise.
        offset - the offset within byteArray of the data to start deserialisation from.
        length - the length of data within byteArray to be read.
        classLoader - the class loader to be used during deserialisation.
        Returns:
        the deserialised object, or null if a null value was stored.
        Throws:
        IOException - if an I/O error occurs.
      • toStreamAndGetType

        public static FastSerialize.SerialisableType toStreamAndGetType​(Object obj,
                                                                        DataOutput out)
                                                                 throws IOException
        Serialise an object to a stream using the FastSerializable approach where possible. If the object cannot be stored using this approach, then the object is stored using standard Java serialisation.

        The resulting stream may be deserialised using fromStream(DataInput, ClassLoader).

        Parameters:
        obj - the object to serialise. May be null.
        out - the stream to serialise to
        Returns:
        the serialisable type that the object was serialised with.
        Throws:
        IOException - if an I/O error occurs.
      • toStream

        public static void toStream​(Object obj,
                                    DataOutput out)
                             throws IOException
        Serialise an object to a stream using the FastSerializable approach where possible. If the object cannot be stored using this approach, then the object is stored using standard Java serialisation.

        The resulting stream may be deserialised using fromStream(DataInput, ClassLoader).

        Parameters:
        obj - the object to serialise. May be null.
        out - the stream to serialise to
        Throws:
        IOException - if an I/O error occurs.
      • fromStream

        public static Object fromStream​(DataInput in,
                                        ClassLoader classLoader)
                                 throws IOException
        Deserialise an object from a stream using the FastSerializable where possible. The stream data should have been generated by toStream(Object, DataOutput).
        Parameters:
        in - the stream to deserialise.
        classLoader - the class loader to be used during deserialisation.
        Returns:
        the deserialised object, or null if a null value was stored.
        Throws:
        IOException - if an I/O error occurs.