eneter.messaging.dataprocessing.serializing
Class GZipSerializer

java.lang.Object
  extended by eneter.messaging.dataprocessing.serializing.GZipSerializer
All Implemented Interfaces:
ISerializer

public class GZipSerializer
extends java.lang.Object
implements ISerializer

Serializer compressing and decompressing data. The serializer internally uses GZipStream to compress and decompress data.

 Example shows how to serialize data.
 
// Creat the serializer. GZipSerializer aSerializer = new GZipSerializer(); // Create some data to be serialized. MyData aData = new MyData(); ... // Serialize data. Serialized data will be compressed. object aSerializedData = aSerializer.serialize(aData, MyData.class); ... // Deserialize data MyData aDeserialized = aSerializer.deserialize(aSerializedData, MyData.class);


Constructor Summary
GZipSerializer()
          Constructs the serializer with XmlStringSerializer as the underlying serializer.
GZipSerializer(ISerializer underlyingSerializer)
          Constructs the serializer with the given underlying serializer.
 
Method Summary
<T> T
deserialize(java.lang.Object serializedData, java.lang.Class<T> clazz)
          Deserializes compressed data into the specified type.
<T> java.lang.Object
serialize(T dataToSerialize, java.lang.Class<T> clazz)
          Serializes the given data with using the compression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GZipSerializer

public GZipSerializer()
Constructs the serializer with XmlStringSerializer as the underlying serializer. The serializer uses the underlying serializer to serialize data before the compression. It also uses the underlying serializer to deserialize decompressed data.


GZipSerializer

public GZipSerializer(ISerializer underlyingSerializer)
Constructs the serializer with the given underlying serializer. The serializer uses the underlying serializer to serialize data before the compression. It also uses the underlying serializer to deserialize decompressed data.

Parameters:
underlyingSerializer -
Method Detail

serialize

public <T> java.lang.Object serialize(T dataToSerialize,
                                      java.lang.Class<T> clazz)
                           throws java.lang.Exception
Serializes the given data with using the compression.

Specified by:
serialize in interface ISerializer
Parameters:
dataToSerialize - Data to be serialized.
clazz - represents the serialized type.
Returns:
Object representing the serialized data. Based on the serializer implementation it can be byte[] or String.
Throws:
java.lang.Exception - If the serialization fails.

deserialize

public <T> T deserialize(java.lang.Object serializedData,
                         java.lang.Class<T> clazz)
              throws java.lang.Exception
Deserializes compressed data into the specified type.

Specified by:
deserialize in interface ISerializer
Parameters:
serializedData - Data to be deserialized.
Returns:
Deserialized object.
Throws:
java.lang.Exception - If the deserialization fails.