Class SerializationUtils


  • @ThreadSafe
    public final class SerializationUtils
    extends java.lang.Object
    Serialization related utility methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.Serializable deserialize​(byte[] bytes)
      Deserializes a byte array into an object.
      static java.io.Serializable deserialize​(byte[] bytes, java.lang.String errorMessage)
      Wrapper around #deserialize(Object) which throws a runtime exception with the given message on failure.
      static <S,​T extends java.io.Serializable>
      java.util.Map<S,​java.util.ArrayList<T>>
      makeValuesSerializable​(java.util.Map<S,​java.util.Collection<T>> map)  
      static java.lang.String parseBenchmarkResult​(java.lang.String result)
      Parse the actual JSON result from the benchmark output.
      static byte[] serialize​(java.lang.Object obj)
      Serializes an object into a byte array.
      static byte[] serialize​(java.lang.Object obj, java.lang.String errorMessage)
      Wrapper around serialize(Object) which throws a runtime exception with the given message on failure.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • serialize

        public static byte[] serialize​(java.lang.Object obj)
                                throws java.io.IOException
        Serializes an object into a byte array. When the object is null, returns null.
        Parameters:
        obj - the object to serialize
        Returns:
        the serialized bytes
        Throws:
        java.io.IOException - if the serialization fails
      • serialize

        public static byte[] serialize​(java.lang.Object obj,
                                       java.lang.String errorMessage)
        Wrapper around serialize(Object) which throws a runtime exception with the given message on failure.
        Parameters:
        obj - the object the serialize
        errorMessage - the message to show if serialization fails
        Returns:
        the serialized bytes
      • deserialize

        public static java.io.Serializable deserialize​(byte[] bytes)
                                                throws java.io.IOException,
                                                       java.lang.ClassNotFoundException
        Deserializes a byte array into an object. When the bytes are null, returns null.
        Parameters:
        bytes - the byte array to deserialize
        Returns:
        the deserialized object
        Throws:
        java.io.IOException - if the deserialization fails
        java.lang.ClassNotFoundException - if no class found to deserialize into
      • deserialize

        public static java.io.Serializable deserialize​(byte[] bytes,
                                                       java.lang.String errorMessage)
        Wrapper around #deserialize(Object) which throws a runtime exception with the given message on failure.
        Parameters:
        bytes - the byte array the deserialize
        errorMessage - the message to show if deserialization fails
        Returns:
        the deserialized object
      • makeValuesSerializable

        public static <S,​T extends java.io.Serializable> java.util.Map<S,​java.util.ArrayList<T>> makeValuesSerializable​(java.util.Map<S,​java.util.Collection<T>> map)
        Type Parameters:
        S - the key type for the Map
        T - the type of the values in the collections which are the values for the Map
        Parameters:
        map - a map to make serializable
        Returns:
        a copy of the map with serializable values
      • parseBenchmarkResult

        public static java.lang.String parseBenchmarkResult​(java.lang.String result)
        Parse the actual JSON result from the benchmark output. Output might contain interference logs (for example, some warn level logs indicating that the listing file time is too long).
        Parameters:
        result - the output of benchmark
        Returns:
        the actual result in JSON format