java.io

Class ObjectInputStream

Implemented Interfaces:
Closeable, DataInput, ObjectInput, ObjectStreamConstants

public class ObjectInputStream
extends InputStream
implements ObjectInput, ObjectStreamConstants

Nested Class Summary

static class
ObjectInputStream.GetField
This class allows a class to specify exactly which fields should be read, and what values should be read for these fields.

Fields inherited from interface java.io.ObjectStreamConstants

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

Constructor Summary

ObjectInputStream()
Protected constructor that allows subclasses to override deserialization.
ObjectInputStream(InputStream in)
Creates a new ObjectInputStream that will do all of its reading from in.

Method Summary

int
available()
void
close()
Closes the stream represented by this class, thus freeing system resources.
void
defaultReadObject()
Reads the current objects non-transient, non-static fields from the current class from the underlying output stream.
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).
int
read()
int
read(byte[] data, int offset, int length)
boolean
readBoolean()
byte
readByte()
char
readChar()
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.
double
readDouble()
ObjectInputStream.GetField
readFields()
This method should be called by a method called 'readObject' in the deserializing class (if present).
float
readFloat()
void
readFully(data[] )
void
readFully(data[] , int offset, int size)
int
readInt()
String
readLine()
Deprecated.
long
readLong()
Object
readObject()
Returns the next deserialized object read from the underlying stream.
protected Object
readObjectOverride()
This method allows subclasses to override the default de serialization mechanism provided by ObjectInputStream.
short
readShort()
protected void
readStreamHeader()
Reads stream magic and stream version information from the underlying stream.
String
readUTF()
Object
readUnshared()
Returns the next deserialized object read from the underlying stream in an unshared manner.
int
readUnsignedByte()
int
readUnsignedShort()
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 ().
protected Class
resolveClass(ObjectStreamClass osc)
Called when a class is being deserialized.
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.
protected Class
resolveProxyClass(String[] intfs)
int
skipBytes(int len)

Methods inherited from class java.io.InputStream

available, close, mark, markSupported, read, read, read, reset, skip

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

ObjectInputStream

protected ObjectInputStream()
            throws IOException,
                   SecurityException
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.

ObjectInputStream

public ObjectInputStream(InputStream in)
            throws IOException,
                   StreamCorruptedException
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.

Method Details

available

public int available()
            throws IOException
Specified by:
available in interface ObjectInput
Overrides:
available in interface InputStream

close

public void close()
            throws IOException
Closes the stream represented by this class, thus freeing system resources. In that case that the stream is already in the closed state, this method has no effect.
Specified by:
close in interface ObjectInput
close in interface Closeable
Overrides:
close in interface InputStream
Throws:
IOException - if an I/O error occurs in closing.

defaultReadObject

public void defaultReadObject()
            throws ClassNotFoundException,
                   IOException,
                   NotActiveException
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)
            throws SecurityException
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()
            throws IOException
Specified by:
read in interface ObjectInput
Overrides:
read in interface InputStream

read

public int read(byte[] data,
                int offset,
                int length)
            throws IOException
Specified by:
read in interface ObjectInput
Overrides:
read in interface InputStream

readBoolean

public boolean readBoolean()
            throws IOException
Specified by:
readBoolean in interface DataInput

readByte

public byte readByte()
            throws IOException
Specified by:
readByte in interface DataInput

readChar

public char readChar()
            throws IOException
Specified by:
readChar in interface DataInput

readClassDescriptor

protected ObjectStreamClass readClassDescriptor()
            throws ClassNotFoundException,
                   IOException
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.

readDouble

public double readDouble()
            throws IOException
Specified by:
readDouble in interface DataInput

readFields

public ObjectInputStream.GetField readFields()
            throws IOException,
                   ClassNotFoundException,
                   NotActiveException
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 ObjectInputStream.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()
            throws IOException
Specified by:
readFloat in interface DataInput

readFully

public void readFully(data[] )
            throws IOException

readFully

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

readInt

public int readInt()
            throws IOException
Specified by:
readInt in interface DataInput

readLine

public String readLine()
            throws IOException

Deprecated.

Specified by:
readLine in interface DataInput
See Also:
()

readLong

public long readLong()
            throws IOException
Specified by:
readLong in interface DataInput

readObject

public final Object readObject()
            throws ClassNotFoundException,
                   IOException
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.
Specified by:
readObject in interface ObjectInput
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()
            throws ClassNotFoundException,
                   IOException,
                   OptionalDataException
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.

readShort

public short readShort()
            throws IOException
Specified by:
readShort in interface DataInput

readStreamHeader

protected void readStreamHeader()
            throws IOException,
                   StreamCorruptedException
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.

readUTF

public String readUTF()
            throws IOException
Specified by:
readUTF in interface DataInput

readUnshared

public Object readUnshared()
            throws IOException,
                   ClassNotFoundException
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 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.
IOException - if an I/O error occurs from the stream.
Since:
1.4
See Also:
readObject()

readUnsignedByte

public int readUnsignedByte()
            throws IOException
Specified by:
readUnsignedByte in interface DataInput

readUnsignedShort

public int readUnsignedShort()
            throws IOException
Specified by:
readUnsignedShort in interface DataInput

registerValidation

public void registerValidation(ObjectInputValidation validator,
                               int priority)
            throws InvalidObjectException,
                   NotActiveException
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

resolveClass

protected Class resolveClass(ObjectStreamClass osc)
            throws ClassNotFoundException,
                   IOException
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.

resolveObject

protected Object resolveObject(Object obj)
            throws IOException
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.

resolveProxyClass

protected Class resolveProxyClass(String[] intfs)
            throws IOException,
                   ClassNotFoundException

skipBytes

public int skipBytes(int len)
            throws IOException
Specified by:
skipBytes in interface DataInput

ObjectInputStream.java -- Class used to read serialized objects Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.