Package org.apache.accumulo.test.util
Class SerializationUtil
- java.lang.Object
-
- org.apache.accumulo.test.util.SerializationUtil
-
public class SerializationUtil extends Object
Partially based fromSerializationUtils
.For serializing and de-serializing objects.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
deserialize(byte[] objectData)
Deserializes a singleObject
from an array of bytes.static Object
deserialize(InputStream inputStream)
Deserializes anObject
from the specified stream.static Object
deserializeBase64(String str)
static void
deserializeWritable(org.apache.hadoop.io.Writable writable, byte[] objectData)
static void
deserializeWritable(org.apache.hadoop.io.Writable writable, InputStream inputStream)
static void
deserializeWritableBase64(org.apache.hadoop.io.Writable writable, String str)
static byte[]
serialize(Serializable obj)
Serializes anObject
to a byte array for storage/serialization.static void
serialize(Serializable obj, OutputStream outputStream)
Serializes anObject
to the specified stream.static String
serializeBase64(Serializable obj)
static byte[]
serializeWritable(org.apache.hadoop.io.Writable writable)
static void
serializeWritable(org.apache.hadoop.io.Writable obj, OutputStream outputStream)
static String
serializeWritableBase64(org.apache.hadoop.io.Writable writable)
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.
-
-
-
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)
-
serializeBase64
public static String serializeBase64(Serializable obj)
-
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 anObject
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 nulloutputStream
- the stream to write to, must not be null- Throws:
IllegalArgumentException
- ifoutputStream
isnull
-
serialize
public static byte[] serialize(Serializable obj)
Serializes anObject
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 anObject
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
- ifinputStream
isnull
-
deserialize
public static Object deserialize(byte[] objectData)
Deserializes a singleObject
from an array of bytes.- Parameters:
objectData
- the serialized object, must not be null- Returns:
- the deserialized object
- Throws:
IllegalArgumentException
- ifobjectData
isnull
-
-