|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
java.io.ObjectOutputStream
edu.umd.cs.piccolo.util.PObjectOutputStream
public class PObjectOutputStream
PObjectOutputStream is an extension of ObjectOutputStream to handle
optional elements. This is similar to the concept of Java's
"weak references", but applied to object serialization rather than garbage
collection. Here, PObjectOutputStream provides a method,
writeConditionalObject
, which only serializes the specified
object to the stream if there is a strong reference (if it has been written
somewhere else using writeObject()) to that object elsewhere in the stream.
To discover strong references to objects, PObjectOutputStream uses a
two-phase writing process. First, a "discovery" phase is used to find out
what objects are about to be serialized. This works by effectively
serializing the object graph to /dev/null, recording which objects are
unconditionally written using the standard writeObject method. Then, in the
second "write" phase, ObjectOutputStream actually serializes the data to the
output stream. During this phase, calls to writeConditionalObject() will only
write the specified object if the object was found to be serialized during
the discovery stage. If the object was not recorded during the discovery
stage, a an optional null (the default) is unconditionally written in place
of the object. To skip writting out the null use
writeConditionalObject(object, false)
By careful implementation of readObject and writeObject methods, streams serialized using PObjectOutputStream can be deserialized using the standard ObjectInputStream.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.io.ObjectOutputStream |
---|
ObjectOutputStream.PutField |
Field Summary |
---|
Constructor Summary | |
---|---|
PObjectOutputStream(OutputStream out)
Constructs a PObjectOutputStream that wraps the provided OutputStream. |
Method Summary | |
---|---|
protected void |
recordUnconditionallyWritten(Object aRoot)
Performs a scan of objects that can be serialized once. |
void |
reset()
Resets the ObjectOutputStream clearing any memory about objects already being written while it's at it. |
static byte[] |
toByteArray(Object object)
Transform the given object into an array of bytes. |
void |
writeConditionalObject(Object object)
Writes the given object, but only if it was not in the object tree multiple times. |
void |
writeObjectTree(Object object)
Writes the provided object to the underlying stream like an ordination ObjectOutputStream except that it does not record duplicates at all. |
Methods inherited from class java.io.ObjectOutputStream |
---|
annotateClass, annotateProxyClass, close, defaultWriteObject, drain, enableReplaceObject, flush, putFields, replaceObject, useProtocolVersion, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeClassDescriptor, writeDouble, writeFields, writeFloat, writeInt, writeLong, writeObject, writeObjectOverride, writeShort, writeStreamHeader, writeUnshared, writeUTF |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PObjectOutputStream(OutputStream out) throws IOException
out
- underlying outputstream that will receive the serialized
objects
IOException
- when underlying subsystem throws oneMethod Detail |
---|
public static byte[] toByteArray(Object object) throws IOException
object
- the object to be transformed
IOException
- when serialization system throws onepublic void writeObjectTree(Object object) throws IOException
object
- object to be serialized
IOException
- when underlying subsystem throws onepublic void writeConditionalObject(Object object) throws IOException
object
- object to write to the stream.
IOException
- when underlying subsystem throws onepublic void reset() throws IOException
reset
in class ObjectOutputStream
IOException
- when underlying subsystem throws oneprotected void recordUnconditionallyWritten(Object aRoot) throws IOException
aRoot
- Object from which to start the scan
IOException
- when serialization fails
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |