java.io.ObjectOutputStream
An ObjectOutputStream can be used to save Java objects into a stream where
the objects can be loaded later with an ObjectInputStream. Primitive data
(ints, bytes, chars, etc) can also be saved.
Nested Classes
Summary
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,
baseWireHandle
Public Constructors
Protected Constructors
Public Methods
Protected Methods
|
|
|
|
|
void |
close() |
|
|
|
|
|
void |
flush() |
|
|
|
|
|
void |
write(byte[] buffer) |
abstract |
|
|
|
|
void |
write(int oneByte) |
|
|
|
|
|
void |
write(byte[] buffer, int offset, int count) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
write,
write,
write,
writeBoolean,
writeByte,
writeBytes,
writeChar,
writeChars,
writeDouble,
writeFloat,
writeInt,
writeLong,
writeShort,
writeUTF
Details
Public Constructors
public
ObjectOutputStream(OutputStream output)
Constructs a new ObjectOutputStream on the OutputStream
output
. All writes are now filtered through this stream.
Parameters
output
| The non-null OutputStream to filter writes on. |
Throws
IOException
| If an IO exception happened when writing the object stream
header
|
Protected Constructors
protected
ObjectOutputStream()
Constructs a new
ObjectOutputStream
. The representation
and proper initialization is in the hands of subclasses.
Public Methods
public
void
close()
Close this ObjectOutputStream. Any buffered data is flushed. This
implementation closes the target stream.
Throws
IOException
| If an error occurs attempting to close this stream.
|
public
void
defaultWriteObject()
Default method to write objects into the receiver. Fields defined in the
object's class and superclasses (which are Serializable) will be saved.
Throws
IOException
| If an IO error occurs attempting to write the object data |
public
void
flush()
Flush this ObjectOutputStream. Any pending writes to the underlying
stream are written out when this method is invoked.
Throws
IOException
| If an error occurs attempting to flush this
ObjectOutputStream.
|
Return the
PutField
object for the receiver. This allows
users to transfer values from actual object fields in the object being
dumped to the emulated fields represented by the
PutField
returned by this method.
Returns
- the PutFieldObject for the receiver
public
void
reset()
Reset the receiver. A marker is written to the stream, so that
deserialization will also perform a rest at the same point. Objects
previously written are no longer remembered, so they will be written
again (instead of a cyclical reference) if found in the object graph.
Throws
IOException
| If any IO problem occurred when trying to reset the receiver
|
public
void
useProtocolVersion(int version)
Set the receiver to use the given protocol version.
Parameters
version
| protocol version to be used |
public
void
write(byte[] buffer, int offset, int length)
Writes
length
bytes
from the byte array
buffer
starting at offset
offset
to the
ObjectOutputStream.
Parameters
buffer
| the buffer to be written |
offset
| offset in buffer to get bytes |
length
| number of bytes in buffer to write |
Throws
IOException
| If an error occurs attempting to write to this OutputStream.
|
public
void
write(int value)
Write one byte (
value
) into the receiver's underlying
stream.
Parameters
value
| The primitive data to write. Only the lower byte is written. |
Throws
IOException
| If an IO exception happened when writing the byte.
|
public
void
write(byte[] buffer)
Writes the entire contents of the byte array
buffer
to
this ObjectOutputStream.
Parameters
buffer
| the buffer to be written |
Throws
IOException
| If an error occurs attempting to write to this
ObjectOutputStream.
|
public
void
writeBoolean(boolean value)
Write primitive data of type boolean (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeByte(int value)
Write primitive data of type byte (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeBytes(String value)
Write a String as a sequence of bytes (only lower-order 8 bits of each
char are written), as primitive data (
value
) into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeChar(int value)
Write primitive data of type char (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeChars(String value)
Write a String as a sequence of char, as primitive data (
value
)
into the receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeDouble(double value)
Write primitive data of type double (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeFields()
Write the fields of the object being dumped. The stream will use the
currently active
PutField
object, allowing users to dump
emulated fields, for cross-loading compatibility when a class definition
changes.
public
void
writeFloat(float value)
Write primitive data of type float (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeInt(int value)
Write primitive data of type int (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeLong(long value)
Write primitive data of type long (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
final
void
writeObject(Object object)
Write object
object
into the receiver's underlying stream.
Parameters
object
| The object to write |
Throws
IOException
| If an IO exception happened when writing the object |
public
void
writeShort(int value)
Write primitive data of type short (
value
)into the
receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeUTF(String value)
Write primitive data of type String (
value
) in UTF
format into the receiver's underlying stream.
Parameters
value
| The primitive data to write |
Throws
IOException
| If an IO exception happened when writing the primitive data.
|
public
void
writeUnshared(Object object)
Write object
object
into the receiver's underlying stream
unshared with previously written identical objects.
Parameters
object
| The object to write |
Throws
IOException
| If an IO exception happened when writing the object |
Protected Methods
protected
void
annotateClass(Class<?> aClass)
Writes optional information for class
aClass
into the
stream represented by the receiver. This optional data can be read when
deserializing the class descriptor (ObjectStreamClass) for this class
from the input stream. By default no extra data is saved.
Parameters
aClass
| The class to annotate |
Throws
IOException
| If an IO exception happened when annotating the class. |
protected
void
annotateProxyClass(Class<?> aClass)
Writes optional information for a proxy class into the stream represented
by the receiver. This optional data can be read when deserializing the
proxy class from the input stream. By default no extra data is saved.
Parameters
aClass
| The proxy class to annotate |
Throws
IOException
| If an IO exception happened when annotating the class. |
protected
void
drain()
Flushes buffered primitive data into the receiver.
Throws
IOException
| If an error occurs attempting to drain the data
|
protected
boolean
enableReplaceObject(boolean enable)
Enables/disables object replacement for the receiver. By default this is
not enabled. Only trusted subclasses (loaded with system class loader)
can override this behavior.
Parameters
enable
| if true, enables replacement. If false, disables replacement. |
Returns
- boolean the previous configuration (if it was enabled or
disabled)
protected
Object
replaceObject(Object object)
If
enableReplaceObject()
was activated, computes the
replacement object for the original object
object
and
returns the replacement. Otherwise returns
object
.
Parameters
object
| Original object for which a replacement may be defined |
Returns
- a possibly new, replacement object for
object
Throws
IOException
| If any IO problem occurred when trying to resolve the object. |
protected
void
writeClassDescriptor(ObjectStreamClass classDesc)
Write class descriptor
classDesc
into the receiver.
Parameters
classDesc
| The ObjectStreamClass object to dump |
Throws
IOException
| If an IO exception happened when writing the class
descriptor.
|
protected
void
writeObjectOverride(Object object)
Method to be overridden by subclasses to write
object
into
the receiver's underlying stream.
Throws
IOException
| If an IO exception happened when writing the object
|
protected
void
writeStreamHeader()
Writes the ObjectOutputStream header into the underlying stream.
Throws
IOException
| If an IO exception happened when writing the stream header.
|