com.devexperts.io
Class Marshalled<T>

java.lang.Object
  extended by com.devexperts.io.Marshalled<T>

public final class Marshalled<T>
extends Object

Encapsulates lazy Object and byte array forms accessible via corresponding get methods. Conversion from byte array to object is perfromed lazily and results of conversion are cached. This object is not serializable by itself, but IOUtil.objectToBytes(Object) and IOUtil.writeObject(DataOutput, Object) methods understand this object and use the result of getBytes() invocation.


Method Summary
 boolean equals(Object obj)
           
static
<T> Marshalled<T>
forBytes(byte[] bytes)
           
static
<T> Marshalled<T>
forObject(T object)
           
 byte[] getBytes()
          Returns byte array representation of this marshalled object.
 T getObject()
          Returns object representation of this marshalled object.
 T getObject(ClassLoader cl)
          Returns object representation of this marshalled object.
 int hashCode()
           
 String toString()
           
static Object unwrap(Object object)
          Unwraps Marshalled argument via getObject() call or returns object unmodified.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

unwrap

public static Object unwrap(Object object)
Unwraps Marshalled argument via getObject() call or returns object unmodified.


forObject

public static <T> Marshalled<T> forObject(T object)

forBytes

public static <T> Marshalled<T> forBytes(byte[] bytes)

getObject

public T getObject()
Returns object representation of this marshalled object.

Throws:
MarshallingException - if object cannot be deserialized from its byte array

getObject

public T getObject(ClassLoader cl)
Returns object representation of this marshalled object.

Parameters:
cl - the ClassLoader that will be used to load classes; null for default
Throws:
MarshallingException - if object cannot be deserialized from its byte array

getBytes

public byte[] getBytes()
Returns byte array representation of this marshalled object.

Throws:
MarshallingException - if object cannot be serialized to byte array

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Devexperts. All Rights Reserved.