Android
java.io
public class

java.io.ObjectOutputStream

java.lang.Object
java.io.OutputStream Closeable Flushable
java.io.ObjectOutputStream ObjectOutput ObjectStreamConstants

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
ObjectOutputStream.PutField Inner class to provide access to serializable fields  

Summary

Constants inherited from interface java.io.ObjectStreamConstants

Public Constructors

            ObjectOutputStream(OutputStream output)
Constructs a new ObjectOutputStream on the OutputStream output.

Protected Constructors

            ObjectOutputStream()
Constructs a new ObjectOutputStream.

Public Methods

          void  close()
Close this ObjectOutputStream.
          void  defaultWriteObject()
Default method to write objects into the receiver.
          void  flush()
Flush this ObjectOutputStream.
          ObjectOutputStream.PutField  putFields()
Return the PutField object for the receiver.
          void  reset()
Reset the receiver.
          void  useProtocolVersion(int version)
Set the receiver to use the given protocol version.
          void  write(byte[] buffer, int offset, int length)
Writes length bytes from the byte array buffer starting at offset offset to the ObjectOutputStream.
          void  write(int value)
Write one byte (value) into the receiver's underlying stream.
          void  write(byte[] buffer)
Writes the entire contents of the byte array buffer to this ObjectOutputStream.
          void  writeBoolean(boolean value)
Write primitive data of type boolean (value)into the receiver's underlying stream.
          void  writeByte(int value)
Write primitive data of type byte (value)into the receiver's underlying stream.
          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.
          void  writeChar(int value)
Write primitive data of type char (value)into the receiver's underlying stream.
          void  writeChars(String value)
Write a String as a sequence of char, as primitive data (value) into the receiver's underlying stream.
          void  writeDouble(double value)
Write primitive data of type double (value)into the receiver's underlying stream.
          void  writeFields()
Write the fields of the object being dumped.
          void  writeFloat(float value)
Write primitive data of type float (value)into the receiver's underlying stream.
          void  writeInt(int value)
Write primitive data of type int (value)into the receiver's underlying stream.
          void  writeLong(long value)
Write primitive data of type long (value)into the receiver's underlying stream.
    final      void  writeObject(Object object)
Write object object into the receiver's underlying stream.
          void  writeShort(int value)
Write primitive data of type short (value)into the receiver's underlying stream.
          void  writeUTF(String value)
Write primitive data of type String (value) in UTF format into the receiver's underlying stream.
          void  writeUnshared(Object object)
Write object object into the receiver's underlying stream unshared with previously written identical objects.

Protected Methods

          void  annotateClass(Class<?> aClass)
Writes optional information for class aClass into the stream represented by the receiver.
          void  annotateProxyClass(Class<?> aClass)
Writes optional information for a proxy class into the stream represented by the receiver.
          void  drain()
Flushes buffered primitive data into the receiver.
          boolean  enableReplaceObject(boolean enable)
Enables/disables object replacement for the receiver.
          Object  replaceObject(Object object)
If enableReplaceObject() was activated, computes the replacement object for the original object object and returns the replacement.
          void  writeClassDescriptor(ObjectStreamClass classDesc)
Write class descriptor classDesc into the receiver.
          void  writeObjectOverride(Object object)
Method to be overridden by subclasses to write object into the receiver's underlying stream.
          void  writeStreamHeader()
Writes the ObjectOutputStream header into the underlying stream.
Methods inherited from class java.io.OutputStream
Methods inherited from class java.lang.Object
Methods inherited from interface java.io.Closeable
Methods inherited from interface java.io.DataOutput
Methods inherited from interface java.io.Flushable
Methods inherited from interface java.io.ObjectOutput

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.

Throws

IOException
SecurityException if subclassing this is not allowed
IOException

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.

public ObjectOutputStream.PutField putFields()

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

Throws

IOException If an IO error occurs
NotActiveException If this method is not called from writeObject()

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

Throws

IOException If an IO error occurs

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.

Throws

IOException If an IO error occurs

See Also

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

See Also

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

See Also

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)

Throws

SecurityException If the class of the receiver is not trusted

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.

Parameters

object the object

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.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56