Class PObjectOutputStream
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,ObjectOutput,ObjectStreamConstants,AutoCloseable
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 Class Summary
Nested classes/interfaces inherited from class java.io.ObjectOutputStream
ObjectOutputStream.PutField -
Field Summary
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, SERIAL_FILTER_PERMISSION, 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 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a PObjectOutputStream that wraps the provided OutputStream. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidPerforms a scan of objects that can be serialized once.voidreset()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.voidwriteConditionalObject(Object object) Writes the given object, but only if it was not in the object tree multiple times.voidwriteObjectTree(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, writeUTFMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
PObjectOutputStream
Constructs a PObjectOutputStream that wraps the provided OutputStream.- Parameters:
out- underlying outputstream that will receive the serialized objects- Throws:
IOException- when underlying subsystem throws one
-
-
Method Details
-
toByteArray
Transform the given object into an array of bytes.- Parameters:
object- the object to be transformed- Returns:
- array of bytes representing the given object
- Throws:
IOException- when serialization system throws one
-
writeObjectTree
Writes the provided object to the underlying stream like an ordination ObjectOutputStream except that it does not record duplicates at all.- Parameters:
object- object to be serialized- Throws:
IOException- when underlying subsystem throws one
-
writeConditionalObject
Writes the given object, but only if it was not in the object tree multiple times.- Parameters:
object- object to write to the stream.- Throws:
IOException- when underlying subsystem throws one
-
reset
Resets the ObjectOutputStream clearing any memory about objects already being written while it's at it.- Overrides:
resetin classObjectOutputStream- Throws:
IOException- when underlying subsystem throws one
-
recordUnconditionallyWritten
Performs a scan of objects that can be serialized once.- Parameters:
aRoot- Object from which to start the scan- Throws:
IOException- when serialization fails
-