Task.Support.CoreSupport
Class ZipObject<T extends java.io.Serializable>

java.lang.Object
  extended by Task.Support.CoreSupport.ZipObject<T>
All Implemented Interfaces:
java.io.Serializable

public class ZipObject<T extends java.io.Serializable>
extends java.lang.Object
implements java.io.Serializable

ZipObject is a utility class for compressing and decompressing any object. The idea is to compress object parameters before passing them to remote objects. The reason for doing this is improving network transmission speeds. With most customers using modems, compressing any data transmission even by 50% is a great help. Since most transmissions are textual, the compression should be even better on those.

This class uses Serialization, ObjectIn/OutputStreams, and ByteArrayIn/OutputStreams.

Version:
1.0

Creation Date : 9/3/1999 Creation Time : 8:00pm

Author:
Nazmul Bin Idris
See Also:
Serialized Form

Field Summary
protected  byte[] buffer
          Internal byteArray buffer for storing the compressed Serializable obj
 
Constructor Summary
ZipObject(T obj)
          Constructor for a ZipObject given an uncompressed object.
 
Method Summary
static ZipObject fromBytes(byte[] bytes)
          Given a byte[] which contains the output of toBytes(), allows the original uncompressed object to be reconstituted... using getObject().
static ZipObject fromInputStream(java.io.InputStream is)
          Given an InputStream which contains the output of toBytes(), allows the original uncompressed object to be reconstituted... using getObject().
 T getObject()
          this method extracts the compress object (from this ZipObject) and returns it.
 int getSize()
           
 java.lang.String getSizeString()
           
static void main(java.lang.String[] args)
          SELF TEST METHOD
 byte[] toBytes()
          simply returns the internal byte array used to store the ZipObject data in
 java.io.InputStream toInputStream()
          returns an InputStream that can read from the buffer of the ZipObject
 java.lang.String toString()
          returns a string representation of the ZipObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buffer

protected byte[] buffer
Internal byteArray buffer for storing the compressed Serializable obj

Constructor Detail

ZipObject

public ZipObject(T obj)
          throws ZipObjectException
Constructor for a ZipObject given an uncompressed object.

Parameters:
obj - Uncompressed Serializable object which has to be compressed
Throws:
ZipObjectException - this is thrown if the object couldnt be compressed for whatever reason
Method Detail

toString

public java.lang.String toString()
returns a string representation of the ZipObject

Overrides:
toString in class java.lang.Object

toBytes

public byte[] toBytes()
               throws ZipObjectException
simply returns the internal byte array used to store the ZipObject data in

Returns:
array of bytes used by ZipObject to store compressed data
Throws:
ZipObjectException

toInputStream

public java.io.InputStream toInputStream()
                                  throws ZipObjectException
returns an InputStream that can read from the buffer of the ZipObject

Throws:
ZipObjectException

getSize

public int getSize()

getSizeString

public java.lang.String getSizeString()

fromBytes

public static ZipObject fromBytes(byte[] bytes)
                           throws java.lang.IllegalArgumentException
Given a byte[] which contains the output of toBytes(), allows the original uncompressed object to be reconstituted... using getObject().

Throws:
java.lang.IllegalArgumentException

fromInputStream

public static ZipObject fromInputStream(java.io.InputStream is)
                                 throws java.io.IOException,
                                        java.lang.IllegalArgumentException
Given an InputStream which contains the output of toBytes(), allows the original uncompressed object to be reconstituted... using getObject().

Throws:
java.io.IOException
java.lang.IllegalArgumentException

getObject

public final T getObject()
                                               throws ZipObjectException
this method extracts the compress object (from this ZipObject) and returns it.

Returns:
returns the uncompressed object contained in this ZipObject
Throws:
ZipObjectException - this is thrown if the object could not be uncompressed for whatever reason

main

public static void main(java.lang.String[] args)
SELF TEST METHOD

Parameters:
args - command line args


Copyright © 2011. All Rights Reserved.