The Compact Object Stream Format

Compact object streams give you flexibility. When this kind of object stream is created, it is chained to a concrete data stream that, in turn, implements the input and output of primitive types. This means that the same object stream can be used to read or write data in many formats, such as ASCII and native binary, on many types of media, such as files, strings, and XDR. This format is not self-describing; it passes information about the object’s state only. Compact object streams can interoperate with virtual streams and collectable objects.

Object Streams With Data Streams

Compact object streams work with any stream of type RWDataOutputStream or RWDataInputStream. You can choose a data stream from the Streams package, such as the RWDataToByteOutputStreamImp and RWDataFromByteInputStreamImp classes. For the full selection of streams, see The Data Streams

You can also use the data stream in the Serialization package, which is an adapter to the Essential Tools Module virtual streams.

Object Streams With Virtual Streams

Object streams work with virtual streams through adapters. If a serializable object needs to be saved or restored from a virtual stream, then an object stream can be constructed from the virtual stream using the RWDataFromVirtualInputStreamImp and RWDataToVirtualOutputStreamImp adapter classes. (See Writing to and Reading from Compact Object Streams.)

The adapter enables you to format the primitive types in any way virtual streams can:

portable ascii, RWpistream/RWpostream. This format is human-readable (to a point), but it is bigger and slower than the other options.

portable binary, RWeistream/RWeostream. This format is smaller and faster than ascii, but it is not human-readable.

native binary, RWbistream/RWbostream.This format is slightly smaller and faster than portable binary, but it is non-portable and not human-readable.

Object Streams With Collectable Objects

Collectable objects can also be saved and restored to object streams using the adapter classes RWvistreamFromDataInputStream and RWvostreamToDataOutputStream in the Streams package. Operators are included to handle this process automatically. See The RWvistreamFromDataInputStream Class and The RWvostreamToDataOutputStream Class for instructions.

The Persistence facility in the Essential Tools Module and the Serialization package operate together and can be freely mixed in applications.