All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class au.com.pharos.packing.Packing

au.com.pharos.packing.Packing

public abstract class Packing
A packing Packing defines a method of converting an object to and from an array of bytes for storage in a database.

Generally, each packing Packing should be reflexive: that is, converting any object to and from an array of bytes should yield the same object, or an object appropriately equivalent.

Some Packing subclasses may not be able to pack all objects, or may not be able to unpack an object from some byte arrays. For example, only Strings can safely be stored as string representations, and not all arrays are valid Java serialization forms. In this case, the Packing object should throw an IllegalArgumentException from toBytes() or toBytes().

In both cases, null references should be passed through unchanged.

Example:

    Packing strategy = new StringPacking();
    byte[] raw = strategy.toBytes("Hello world");
    ... store and retrieve raw[]
    String result = (String) strategy.fromBytes(raw)
 

Version:
$Revision: 1.4 $
Author:
Martin Pool
See Also:
StringPacking, NativeStringPacking, RawPacking, SerializationPacking

Constructor Index

 o Packing()

Method Index

 o cantConvert(Object)
Helper function that generates an IllegalArgumentException
 o fromBytes(byte[])
Reconstitute an array of bytes into an object.
 o toBytes(Object)
Convert an object to an array of bytes.

Constructors

 o Packing
 public Packing()

Methods

 o toBytes
 public abstract byte[] toBytes(Object obj) throws IllegalArgumentException
Convert an object to an array of bytes.

 o fromBytes
 public abstract Object fromBytes(byte raw[]) throws IllegalArgumentException
Reconstitute an array of bytes into an object.

 o cantConvert
 protected IllegalArgumentException cantConvert(Object obj)
Helper function that generates an IllegalArgumentException


All Packages  Class Hierarchy  This Package  Previous  Next  Index