edu.umd.cs.piccolo.util
Class PObjectOutputStream
java.lang.Object
java.io.OutputStream
java.io.ObjectOutputStream
edu.umd.cs.piccolo.util.PObjectOutputStream
- All Implemented Interfaces:
- java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.io.ObjectOutput, java.io.ObjectStreamConstants
public class PObjectOutputStream
- extends java.io.ObjectOutputStream
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.
- Version:
- 1.0
- Author:
- Jon Meyer, Jesse Grosjean
Nested classes/interfaces inherited from class java.io.ObjectOutputStream |
java.io.ObjectOutputStream.PutField |
Fields inherited from interface java.io.ObjectStreamConstants |
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING |
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 |
PObjectOutputStream
public PObjectOutputStream(java.io.OutputStream out)
throws java.io.IOException
- Throws:
java.io.IOException
toByteArray
public static byte[] toByteArray(java.lang.Object aRoot)
throws java.io.IOException
- Throws:
java.io.IOException
writeObjectTree
public void writeObjectTree(java.lang.Object aRoot)
throws java.io.IOException
- Throws:
java.io.IOException
writeConditionalObject
public void writeConditionalObject(java.lang.Object object)
throws java.io.IOException
- Throws:
java.io.IOException
reset
public void reset()
throws java.io.IOException
- Overrides:
reset
in class java.io.ObjectOutputStream
- Throws:
java.io.IOException
recordUnconditionallyWritten
protected void recordUnconditionallyWritten(java.lang.Object aRoot)
throws java.io.IOException
- Throws:
java.io.IOException
Copyright © 2008 by University of Maryland, College Park, MD 20742, USA All rights reserved.