Android
java.io
public class

java.io.ObjectInputStream

java.lang.Object
java.io.InputStream Closeable
java.io.ObjectInputStream ObjectInput ObjectStreamConstants

An ObjectInputStream can be used to load Java objects from a stream where the objects were saved using an ObjectOutputStream. Primitive data (ints, bytes, chars, etc) can also be loaded if the data was saved as primitive types as well. It is invalid to attempt to read an object as primitive data.

Nested Classes
ObjectInputStream.GetField Inner class to provide access to serializable fields  

Summary

Constants inherited from interface java.io.ObjectStreamConstants

Public Constructors

            ObjectInputStream(InputStream input)
Constructs a new ObjectInputStream on the InputStream input.

Protected Constructors

            ObjectInputStream()
Constructs a new ObjectInputStream.

Public Methods

          int  available()
Returns the number of bytes of primitive data available from the receiver.
          void  close()
Close this ObjectInputStream.
          void  defaultReadObject()
Default method to read objects from the receiver.
          int  read(byte[] buffer, int offset, int length)
Reads at most length bytes from the receiver and stores them in byte array buffer starting at offset offset.
          int  read()
Reads a single byte from the receiver and returns the result as an int.
          boolean  readBoolean()
Reads and returns primitive data of type boolean read from the receiver
          byte  readByte()
Reads and returns primitive data of type byte read from the receiver
          char  readChar()
Reads and returns primitive data of type char read from the receiver
          double  readDouble()
Reads and returns primitive data of type double read from the receiver
          ObjectInputStream.GetField  readFields()
Reads the fields of the object being read from the stream.
          float  readFloat()
Reads and returns primitive data of type float read from the receiver
          void  readFully(byte[] buffer, int offset, int length)
Reads bytes from the receiver into the byte array buffer.
          void  readFully(byte[] buffer)
Reads bytes from the receiver into the byte array buffer.
          int  readInt()
Reads and returns primitive data of type int read from the receiver
          String  readLine()
This method is deprecated. Use BufferedReader
          long  readLong()
Reads and returns primitive data of type long read from the receiver
    final      Object  readObject()
Read the next object from the receiver's underlying stream.
          short  readShort()
Reads and returns primitive data of type short from the receiver
          String  readUTF()
Reads and returns primitive data of type String read in UTF format from the receiver
          Object  readUnshared()
Read the next unshared object from the receiver's underlying stream.
          int  readUnsignedByte()
Reads and returns primitive data of type byte (unsigned) from the receiver
          int  readUnsignedShort()
Reads and returns primitive data of type short (unsigned) from the receiver
  synchronized        void  registerValidation(ObjectInputValidation object, int priority)
Register object validator object to be executed to perform validation of objects loaded from the receiver.
          int  skipBytes(int length)
Skips length bytes of primitive data from the receiver.

Protected Methods

          boolean  enableResolveObject(boolean enable)
Enables/disables object replacement for the receiver.
          ObjectStreamClass  readClassDescriptor()
Reads a new class descriptor from the receiver.
          Object  readObjectOverride()
Method to be overriden by subclasses to read the next object from the receiver's underlying stream.
          void  readStreamHeader()
Reads and validates the ObjectInputStream header from the receiver
          Class<?>  resolveClass(ObjectStreamClass osClass)
Loads the Java class corresponding to the class descriptor osClass(ObjectStreamClass) just read from the receiver.
          Object  resolveObject(Object object)
If enableResolveObject() was activated, computes the replacement object for the original object object and returns the replacement.
          Class<?>  resolveProxyClass(String[] interfaceNames)
Retrieves the proxy class corresponding to the interface names.
Methods inherited from class java.io.InputStream
Methods inherited from class java.lang.Object
Methods inherited from interface java.io.Closeable
Methods inherited from interface java.io.DataInput
Methods inherited from interface java.io.ObjectInput

Details

Public Constructors

public ObjectInputStream(InputStream input)

Constructs a new ObjectInputStream on the InputStream input. All reads are now filtered through this stream.

Parameters

input The non-null InputStream to filter reads on.

Throws

IOException If an IO exception happened when reading the stream header.
StreamCorruptedException If the underlying stream does not contain serialized objects that can be read.

Protected Constructors

protected ObjectInputStream()

Constructs a new ObjectInputStream. The representation and proper initialization is on the hands of subclasses.

Throws

IOException If not called from a subclass
SecurityException If subclasses are not allowed

Public Methods

public int available()

Returns the number of bytes of primitive data available from the receiver. It should not be used at any arbitrary position; just when reading primitive data types (ints, chars, etc).

Returns

  • the number of available primitive data bytes

Throws

IOException If any IO problem occurred when trying to compute the bytes available.

public void close()

Close this ObjectInputStream. This implementation closes the target stream.

Throws

IOException If an error occurs attempting to close this stream.

public void defaultReadObject()

Default method to read objects from the receiver. Fields defined in the object's class and super classes (which are Serializable) will be read.

Throws

IOException If an IO error occurs attempting to read the object data
ClassNotFoundException If the class of the object cannot be found
NotActiveException If this method is not called from readObject()

public int read(byte[] buffer, int offset, int length)

Reads at most length bytes from the receiver and stores them in byte array buffer starting at offset offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered.

Parameters

buffer the byte array in which to store the read bytes.
offset the offset in buffer to store the read bytes.
length the maximum number of bytes to store in buffer.

Returns

  • The number of bytes actually read or -1 if end of stream.

Throws

IOException If an IO exception happened when reading the primitive data.

public int read()

Reads a single byte from the receiver and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered.

Returns

  • The byte read or -1 if end of stream.

Throws

IOException If an IO exception happened when reading the primitive data.

public boolean readBoolean()

Reads and returns primitive data of type boolean read from the receiver

Returns

  • A boolean saved as primitive data using ObjectOutputStream.writeBoolean()

Throws

IOException If an IO exception happened when reading the primitive data.

public byte readByte()

Reads and returns primitive data of type byte read from the receiver

Returns

  • A byte saved as primitive data using ObjectOutputStream.writeByte()

Throws

IOException If an IO exception happened when reading the primitive data.

public char readChar()

Reads and returns primitive data of type char read from the receiver

Returns

  • A char saved as primitive data using ObjectOutputStream.writeChar()

Throws

IOException If an IO exception happened when reading the primitive data.

public double readDouble()

Reads and returns primitive data of type double read from the receiver

Returns

  • A double saved as primitive data using ObjectOutputStream.writeDouble()

Throws

IOException If an IO exception happened when reading the primitive data.

public ObjectInputStream.GetField readFields()

Reads the fields of the object being read from the stream. The stream will use the currently active getField object, allowing users to load emulated fields, for cross-loading compatibility when a class definition changes.

Returns

  • the fields being read

Throws

IOException If an IO exception happened
ClassNotFoundException If a class of an object being de-serialized can not be found
NotActiveException If there is no object currently being loaded (invalid to call this method)

public float readFloat()

Reads and returns primitive data of type float read from the receiver

Returns

  • A float saved as primitive data using ObjectOutputStream.writeFloat()

Throws

IOException If an IO exception happened when reading the primitive data.

public void readFully(byte[] buffer, int offset, int length)

Reads bytes from the receiver into the byte array buffer. This method will block until length number of bytes have been read.

Parameters

buffer the byte array in which to store the read bytes.
offset the offset in buffer to store the read bytes.
length the maximum number of bytes to store in buffer.

Throws

IOException if a problem occurs reading from this stream.

public void readFully(byte[] buffer)

Reads bytes from the receiver into the byte array buffer. This method will block until buffer.length number of bytes have been read.

Parameters

buffer the buffer to read bytes into

Throws

IOException if a problem occurs reading from this stream.

public int readInt()

Reads and returns primitive data of type int read from the receiver

Returns

  • an int saved as primitive data using ObjectOutputStream.writeInt()

Throws

IOException If an IO exception happened when reading the primitive data.

public String readLine()

This method is deprecated. Use BufferedReader

Reads and returns the next line (primitive data of type String) read from the receiver

Returns

  • a String saved as primitive data using ObjectOutputStream.writeLine()

Throws

IOException If an IO exception happened when reading the primitive data.

public long readLong()

Reads and returns primitive data of type long read from the receiver

Returns

  • a long saved as primitive data using ObjectOutputStream.writeLong()

Throws

IOException If an IO exception happened when reading the primitive data.

public final Object readObject()

Read the next object from the receiver's underlying stream.

Returns

  • the new object read.

Throws

IOException If an IO exception happened when reading the object
ClassNotFoundException If the class of one of the objects in the object graph could not be found
OptionalDataException If primitive data types were found instead of an object.

public short readShort()

Reads and returns primitive data of type short from the receiver

Returns

  • a short saved as primitive data using ObjectOutputStream.writeShort()

Throws

IOException If an IO exception happened when reading the primitive data.

public String readUTF()

Reads and returns primitive data of type String read in UTF format from the receiver

Returns

  • a String saved as primitive data using ObjectOutputStream.writeUTF()

Throws

IOException If an IO exception happened when reading the primitive data.

public Object readUnshared()

Read the next unshared object from the receiver's underlying stream.

Returns

  • the new object read.

Throws

IOException If an IO exception happened when reading the object
ClassNotFoundException If the class of one of the objects in the object graph could not be found

public int readUnsignedByte()

Reads and returns primitive data of type byte (unsigned) from the receiver

Returns

  • a byte saved as primitive data using ObjectOutputStream.writeUnsignedByte()

Throws

IOException If an IO exception happened when reading the primitive data.

public int readUnsignedShort()

Reads and returns primitive data of type short (unsigned) from the receiver

Returns

  • a short saved as primitive data using ObjectOutputStream.writeUnsignedShort()

Throws

IOException If an IO exception happened when reading the primitive data.

public synchronized void registerValidation(ObjectInputValidation object, int priority)

Register object validator object to be executed to perform validation of objects loaded from the receiver. Validations will be run in order of decreasing priority, defined by priority.

Parameters

object An ObjectInputValidation to validate objects loaded.
priority validator priority

Throws

NotActiveException If this method is not called from readObject()
InvalidObjectException If object is null.

public int skipBytes(int length)

Skips length bytes of primitive data from the receiver. It should not be used to skip bytes at any arbitrary position; just when reading primitive data types (ints, chars, etc).

Parameters

length How many bytes to skip

Returns

  • number of bytes skipped

Throws

IOException If any IO problem occurred when trying to skip the bytes.

Protected Methods

protected boolean enableResolveObject(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

  • the previous configuration (if it was enabled or disabled)

Throws

SecurityException If the class of the receiver is not trusted

protected ObjectStreamClass readClassDescriptor()

Reads a new class descriptor from the receiver. Return the class descriptor read.

Returns

  • The ObjectStreamClass read from the stream.

Throws

IOException If an IO exception happened when reading the class descriptor.
ClassNotFoundException If a class for one of the objects could not be found

protected Object readObjectOverride()

Method to be overriden by subclasses to read the next object from the receiver's underlying stream.

Returns

  • the new object read.

Throws

IOException If an IO exception happened when reading the object
ClassNotFoundException If the class of one of the objects in the object graph could not be found
OptionalDataException If primitive data types were found instead of an object.

protected void readStreamHeader()

Reads and validates the ObjectInputStream header from the receiver

Throws

IOException If an IO exception happened when reading the stream header.
StreamCorruptedException If the underlying stream does not contain serialized objects that can be read.

protected Class<?> resolveClass(ObjectStreamClass osClass)

Loads the Java class corresponding to the class descriptor osClass(ObjectStreamClass) just read from the receiver.

Parameters

osClass An ObjectStreamClass read from the receiver.

Returns

  • a Class corresponding to the descriptor loaded.

Throws

IOException If any IO problem occurred when trying to load the class.
ClassNotFoundException If the corresponding class cannot be found.

protected Object resolveObject(Object object)

If enableResolveObject() 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 Class<?> resolveProxyClass(String[] interfaceNames)

Retrieves the proxy class corresponding to the interface names.

Parameters

interfaceNames The interfaces used to create the proxy class

Returns

  • A proxy class

Throws

IOException If any IO problem occurred when trying to load the class.
ClassNotFoundException If the proxy class cannot be created
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56