facets.util
Class PackedSerialized

java.lang.Object
  extended by facets.util.Tracer
      extended by facets.util.PackedSerialized
All Implemented Interfaces:
SizeEstimable

public final class PackedSerialized
extends Tracer
implements SizeEstimable

Converts between Serializables and compressed bytes.


Field Summary
 byte[] packed
          The result of passing a Serializable to the constructor.
 
Constructor Summary
PackedSerialized(java.io.Serializable serializable)
          Unique constructor.
 
Method Summary
 long estimateSize()
           
static PackedSerialized newUnpackChecked(java.io.Serializable s)
          Creates a PackedSerialized that is guaranteed to unpack.
static java.io.Serializable newUnpacked(byte[] packed)
          Attempts to recreate a Serializable from bytes.
 java.lang.String toString()
           
protected  void traceOutput(java.lang.String msg)
          Outputs complete trace messages to console or elsewhere.
 java.io.Serializable unpack()
          Attempts to recreate the Serializable passed to the constructor.
 
Methods inherited from class facets.util.Tracer
trace, trace, trace, trace, trace, traceDebug, traceDebug, traceObjectText, traceOutputWithClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

packed

public final byte[] packed
The result of passing a Serializable to the constructor.

Constructor Detail

PackedSerialized

public PackedSerialized(java.io.Serializable serializable)
Unique constructor.

Parameters:
serializable - will be converted to a compressed byte[] stored as packed
Method Detail

traceOutput

protected void traceOutput(java.lang.String msg)
Description copied from class: Tracer
Outputs complete trace messages to console or elsewhere.

Default prepends helpful classname to message.

Overrides:
traceOutput in class Tracer
Parameters:
msg - passed from one of the public methods

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

unpack

public java.io.Serializable unpack()
Attempts to recreate the Serializable passed to the constructor.

Throws a RuntimeException if recreation fails.


newUnpackChecked

public static PackedSerialized newUnpackChecked(java.io.Serializable s)
Creates a PackedSerialized that is guaranteed to unpack.

Parameters:
s - passed to constructor
Returns:
a PackedSerialized guaranteed to unpack but possibly not compressed

newUnpacked

public static java.io.Serializable newUnpacked(byte[] packed)
Attempts to recreate a Serializable from bytes.

Parameters:
packed - is treated as a valid packed
Returns:
a Serializable or null if recreation fails

estimateSize

public long estimateSize()
Specified by:
estimateSize in interface SizeEstimable