java.io

Class ObjectInputStream

public class ObjectInputStream extends InputStream implements ObjectInput, ObjectStreamConstants

Nested Class Summary
abstract static classObjectInputStream.GetField
This class allows a class to specify exactly which fields should be read, and what values should be read for these fields.
Constructor Summary
ObjectInputStream(InputStream in)
Creates a new ObjectInputStream that will do all of its reading from in.
protected ObjectInputStream()
Protected constructor that allows subclasses to override deserialization.
Method Summary
intavailable()
voidclose()
voiddefaultReadObject()
Reads the current objects non-transient, non-static fields from the current class from the underlying output stream.
protected booleanenableResolveObject(boolean enable)
If enable is true and this object is trusted, then resolveObject (Object) will be called in subsequent calls to readObject (Object).
intread()
intread(byte[] data, int offset, int length)
booleanreadBoolean()
bytereadByte()
charreadChar()
protected ObjectStreamClassreadClassDescriptor()
This method reads a class descriptor from the real input stream and use these data to create a new instance of ObjectStreamClass.
doublereadDouble()
ObjectInputStream.GetFieldreadFields()
This method should be called by a method called 'readObject' in the deserializing class (if present).
floatreadFloat()
voidreadFully(byte[] data)
voidreadFully(byte[] data, int offset, int size)
intreadInt()
StringreadLine()
longreadLong()
ObjectreadObject()
Returns the next deserialized object read from the underlying stream.
protected ObjectreadObjectOverride()
This method allows subclasses to override the default de serialization mechanism provided by ObjectInputStream.
shortreadShort()
protected voidreadStreamHeader()
Reads stream magic and stream version information from the underlying stream.
ObjectreadUnshared()

Returns the next deserialized object read from the underlying stream in an unshared manner.

intreadUnsignedByte()
intreadUnsignedShort()
StringreadUTF()
voidregisterValidation(ObjectInputValidation validator, int priority)
Registers a ObjectInputValidation to be carried out on the object graph currently being deserialized before it is returned to the original caller of readObject ().
protected Class<?>resolveClass(ObjectStreamClass osc)
Called when a class is being deserialized.
protected ObjectresolveObject(Object obj)
Allows subclasses to resolve objects that are read from the stream with other objects to be returned in their place.
protected Class<?>resolveProxyClass(String[] intfs)
intskipBytes(int len)

Constructor Detail

ObjectInputStream

public ObjectInputStream(InputStream in)
Creates a new ObjectInputStream that will do all of its reading from in. This method also checks the stream by reading the header information (stream magic number and stream version).

Throws: IOException Reading stream header from underlying stream cannot be completed. StreamCorruptedException An invalid stream magic number or stream version was read from the stream.

See Also: readStreamHeader

ObjectInputStream

protected ObjectInputStream()
Protected constructor that allows subclasses to override deserialization. This constructor should be called by subclasses that wish to override readObject (Object). This method does a security check NOTE: currently not implemented, then sets a flag that informs readObject (Object) to call the subclasses readObjectOverride (Object) method.

See Also: readObjectOverride

Method Detail

available

public int available()

close

public void close()

defaultReadObject

public void defaultReadObject()
Reads the current objects non-transient, non-static fields from the current class from the underlying output stream. This method is intended to be called from within a object's private void readObject (ObjectInputStream) method.

Throws: ClassNotFoundException The class that an object being read in belongs to cannot be found. NotActiveException This method was called from a context other than from the current object's and current class's private void readObject (ObjectInputStream) method. IOException Exception from underlying OutputStream.

enableResolveObject

protected boolean enableResolveObject(boolean enable)
If enable is true and this object is trusted, then resolveObject (Object) will be called in subsequent calls to readObject (Object). Otherwise, resolveObject (Object) will not be called.

Throws: SecurityException This class is not trusted.

read

public int read()

read

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

readBoolean

public boolean readBoolean()

readByte

public byte readByte()

readChar

public char readChar()

readClassDescriptor

protected ObjectStreamClass readClassDescriptor()
This method reads a class descriptor from the real input stream and use these data to create a new instance of ObjectStreamClass. Fields are sorted and ordered for the real read which occurs for each instance of the described class. Be aware that if you call that method you must ensure that the stream is synchronized, in the other case it may be completely desynchronized.

Returns: A new instance of ObjectStreamClass containing the freshly created descriptor.

Throws: ClassNotFoundException if the required class to build the descriptor has not been found in the system. IOException An input/output error occured. InvalidClassException If there was a compatibility problem between the class present in the system and the serialized class.

readDouble

public double readDouble()

readFields

public ObjectInputStream.GetField readFields()
This method should be called by a method called 'readObject' in the deserializing class (if present). It cannot (and should not)be called outside of it. Its goal is to read all fields in the real input stream and keep them accessible through the {@link GetField} class. Calling this method will not alter the deserializing object.

Returns: A valid freshly created 'GetField' instance to get access to the deserialized stream.

Throws: IOException An input/output exception occured. ClassNotFoundException NotActiveException

readFloat

public float readFloat()

readFully

public void readFully(byte[] data)

readFully

public void readFully(byte[] data, int offset, int size)

readInt

public int readInt()

readLine

public String readLine()

Deprecated:

See Also: readLine

readLong

public long readLong()

readObject

public final Object readObject()
Returns the next deserialized object read from the underlying stream. This method can be overriden by a class by implementing private void readObject (ObjectInputStream). If an exception is thrown from this method, the stream is left in an undefined state. This method can also throw Errors and RuntimeExceptions if caused by existing readResolve() user code.

Returns: The object read from the underlying stream.

Throws: ClassNotFoundException The class that an object being read in belongs to cannot be found. IOException Exception from underlying InputStream.

readObjectOverride

protected Object readObjectOverride()
This method allows subclasses to override the default de serialization mechanism provided by ObjectInputStream. To make this method be used for writing objects, subclasses must invoke the 0-argument constructor on this class from their constructor.

See Also: ObjectInputStream

readShort

public short readShort()

readStreamHeader

protected void readStreamHeader()
Reads stream magic and stream version information from the underlying stream.

Throws: IOException Exception from underlying stream. StreamCorruptedException An invalid stream magic number or stream version was read from the stream.

readUnshared

public Object readUnshared()

Returns the next deserialized object read from the underlying stream in an unshared manner. Any object returned by this method will not be returned by subsequent calls to either this method or {@link #readObject()}.

This behaviour is achieved by:

Returns: a reference to the deserialized object.

Throws: ClassNotFoundException if the class of the object being deserialized can not be found. StreamCorruptedException if information in the stream is inconsistent. ObjectStreamException if the next object has already been returned by an earlier call to this method or {@link #readObject()}. OptionalDataException if primitive data occurs next in the stream. IOException if an I/O error occurs from the stream.

Since: 1.4

See Also: readObject

readUnsignedByte

public int readUnsignedByte()

readUnsignedShort

public int readUnsignedShort()

readUTF

public String readUTF()

registerValidation

public void registerValidation(ObjectInputValidation validator, int priority)
Registers a ObjectInputValidation to be carried out on the object graph currently being deserialized before it is returned to the original caller of readObject (). The order of validation for multiple ObjectInputValidations can be controled using priority. Validators with higher priorities are called first.

Throws: InvalidObjectException validator is null NotActiveException an attempt was made to add a validator outside of the readObject method of the object currently being deserialized

See Also:

resolveClass

protected Class<?> resolveClass(ObjectStreamClass osc)
Called when a class is being deserialized. This is a hook to allow subclasses to read in information written by the annotateClass (Class) method of an ObjectOutputStream. This implementation looks up the active call stack for a ClassLoader; if a ClassLoader is found, it is used to load the class associated with osc, otherwise, the default system ClassLoader is used.

Throws: IOException Exception from underlying OutputStream.

See Also: annotateClass

resolveObject

protected Object resolveObject(Object obj)
Allows subclasses to resolve objects that are read from the stream with other objects to be returned in their place. This method is called the first time each object is encountered. This method must be enabled before it will be called in the serialization process.

Throws: IOException Exception from underlying OutputStream.

See Also: ObjectInputStream

resolveProxyClass

protected Class<?> resolveProxyClass(String[] intfs)

skipBytes

public int skipBytes(int len)