Class SerializationUtil


  • public class SerializationUtil
    extends Object
    Partially based from SerializationUtils.

    For serializing and de-serializing objects.

    • Method Detail

      • subclassNewInstance

        public static <E> E subclassNewInstance​(String classname,
                                                Class<E> parentClass)
        Create a new instance of a class whose name is given, as a descendent of a given subclass.
      • serializeWritableBase64

        public static String serializeWritableBase64​(org.apache.hadoop.io.Writable writable)
      • deserializeWritableBase64

        public static void deserializeWritableBase64​(org.apache.hadoop.io.Writable writable,
                                                     String str)
      • deserializeBase64

        public static Object deserializeBase64​(String str)
      • serializeWritable

        public static byte[] serializeWritable​(org.apache.hadoop.io.Writable writable)
      • serializeWritable

        public static void serializeWritable​(org.apache.hadoop.io.Writable obj,
                                             OutputStream outputStream)
      • deserializeWritable

        public static void deserializeWritable​(org.apache.hadoop.io.Writable writable,
                                               InputStream inputStream)
      • deserializeWritable

        public static void deserializeWritable​(org.apache.hadoop.io.Writable writable,
                                               byte[] objectData)
      • serialize

        public static void serialize​(Serializable obj,
                                     OutputStream outputStream)
        Serializes an Object to the specified stream.

        The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code.

        The stream passed in is not buffered internally within this method. This is the responsibility of your application if desired.

        Parameters:
        obj - the object to serialize to bytes, may be null
        outputStream - the stream to write to, must not be null
        Throws:
        IllegalArgumentException - if outputStream is null
      • serialize

        public static byte[] serialize​(Serializable obj)
        Serializes an Object to a byte array for storage/serialization.
        Parameters:
        obj - the object to serialize to bytes
        Returns:
        a byte[] with the converted Serializable
      • deserialize

        public static Object deserialize​(InputStream inputStream)
        Deserializes an Object from the specified stream.

        The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code.

        The stream passed in is not buffered internally within this method. This is the responsibility of your application if desired.

        Parameters:
        inputStream - the serialized object input stream, must not be null
        Returns:
        the deserialized object
        Throws:
        IllegalArgumentException - if inputStream is null
      • deserialize

        public static Object deserialize​(byte[] objectData)
        Deserializes a single Object from an array of bytes.
        Parameters:
        objectData - the serialized object, must not be null
        Returns:
        the deserialized object
        Throws:
        IllegalArgumentException - if objectData is null