Whole document tree
java.io
|
Inner Class Summary | |
static class |
ObjectInputStream.GetField
Provide access to the persistent fields read from the input stream. |
Constructor Summary | |
protected |
ObjectInputStream()
Provide a way for subclasses that are completely reimplementing ObjectInputStream to not have to allocate private data just used by this implementation of ObjectInputStream. |
|
ObjectInputStream(InputStream in)
Create an ObjectInputStream that reads from the specified InputStream. |
Method Summary | |
int |
available()
Returns the number of bytes that can be read without blocking. |
void |
close()
Closes the input stream. |
void |
defaultReadObject()
Read the non-static and non-transient fields of the current class from this stream. |
protected boolean |
enableResolveObject(boolean enable)
Enable the stream to allow objects read from the stream to be replaced. |
int |
read()
Reads a byte of data. |
int |
read(byte[] b,
int off,
int len)
Reads into an array of bytes. |
boolean |
readBoolean()
Reads in a boolean. |
byte |
readByte()
Reads an 8 bit byte. |
char |
readChar()
Reads a 16 bit char. |
protected ObjectStreamClass |
readClassDescriptor()
Read a class descriptor from the serialization stream. |
double |
readDouble()
Reads a 64 bit double. |
ObjectInputStream.GetField |
readFields()
Reads the persistent fields from the stream and makes them available by name. |
float |
readFloat()
Reads a 32 bit float. |
void |
readFully(byte[] data)
Reads bytes, blocking until all bytes are read. |
void |
readFully(byte[] data,
int offset,
int size)
Reads bytes, blocking until all bytes are read. |
int |
readInt()
Reads a 32 bit int. |
String |
readLine()
Deprecated. This method does not properly convert bytes to characters. see DataInputStream for the details and alternatives. |
long |
readLong()
Reads a 64 bit long. |
Object |
readObject()
Read an object from the ObjectInputStream. |
protected Object |
readObjectOverride()
This method is called by trusted subclasses of ObjectOutputStream that constructed ObjectOutputStream using the protected no-arg constructor. |
short |
readShort()
Reads a 16 bit short. |
protected void |
readStreamHeader()
The readStreamHeader method is provided to allow subclasses to read and verify their own stream headers. |
int |
readUnsignedByte()
Reads an unsigned 8 bit byte. |
int |
readUnsignedShort()
Reads an unsigned 16 bit short. |
String |
readUTF()
Reads a UTF format String. |
void |
registerValidation(ObjectInputValidation obj,
int prio)
Register an object to be validated before the graph is returned. |
protected Class |
resolveClass(ObjectStreamClass v)
Load the local class equivalent of the specified stream class description. |
protected Object |
resolveObject(Object obj)
This method will allow trusted subclasses of ObjectInputStream to substitute one object for another during deserialization. |
protected Class |
resolveProxyClass(String[] interfaces)
Returns a proxy class that implements the interfaces named in a proxy class descriptor; subclasses may implement this method to read custom data from the stream along with the descriptors for dynamic proxy classes, allowing them to use an alternate loading mechanism for the interfaces and the proxy class. |
int |
skipBytes(int len)
Skips bytes, block until all bytes are skipped. |
Methods inherited from class java.io.InputStream |
mark, markSupported, read, reset, skip |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.io.ObjectInput |
read, skip |
Constructor Detail |
public ObjectInputStream(InputStream in) throws IOException, StreamCorruptedException
in
- the underlying InputStream
from which to readStreamCorruptedException
- The version or magic number are
incorrect.IOException
- An exception occurred in the underlying stream.protected ObjectInputStream() throws IOException, SecurityException
If there is a security manager installed, this method first calls the
security manager's checkPermission
method with the
SerializablePermission("enableSubclassImplementation")
permission to ensure it's ok to enable subclassing.
IOException
- Thrown if not called by a subclass.SecurityException
- if a security manager exists and its
checkPermission
method denies
enabling subclassing.SecurityManager.checkPermission(java.security.Permission)
,
SerializablePermission
Method Detail |
public final Object readObject() throws OptionalDataException, ClassNotFoundException, IOException
The root object is completly restored when all of its fields and the objects it references are completely restored. At this point the object validation callbacks are executed in order based on their registered priorities. The callbacks are registered by objects (in the readObject special methods) as they are individually restored. Exceptions are thrown for problems with the InputStream and for classes that should not be deserialized. All exceptions are fatal to the InputStream and leave it in an indeterminate state; it is up to the caller to ignore or recover the stream state.
readObject
in interface ObjectInput
ClassNotFoundException
- Class of a serialized object
cannot be found.InvalidClassException
- Something is wrong with a class used by
serialization.StreamCorruptedException
- Control information in the
stream is inconsistent.OptionalDataException
- Primitive data was found in the
stream instead of objects.IOException
- Any of the usual Input/Output related exceptions.protected Object readObjectOverride() throws OptionalDataException, ClassNotFoundException, IOException
ClassNotFoundException
- Class definition of a
serialized object cannot be found.OptionalDataException
- Primitive data was found in the
stream instead of objects.IOException
- if I/O errors occurred while reading from the
underlying streamObjectInputStream()
,
readObject()
public void defaultReadObject() throws IOException, ClassNotFoundException, NotActiveException
ClassNotFoundException
- if the class of a serialized
object could not be found.IOException
- if an I/O error occurs.NotActiveException
- if the stream is not currently reading
objects.public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException, NotActiveException
GetField
object representing the persistent
fields of the object being deserializedClassNotFoundException
- if the class of a serialized
object could not be found.IOException
- if an I/O error occurs.NotActiveException
- if the stream is not currently reading
objects.public void registerValidation(ObjectInputValidation obj, int prio) throws NotActiveException, InvalidObjectException
obj
- the object to receive the validation callback.prio
- controls the order of callbacks;zero is a good default.
Use higher numbers to be called back earlier, lower numbers for later
callbacks. Within a priority, callbacks are processed in no
particular order.NotActiveException
- The stream is not currently reading
objects so it is invalid to register a callback.InvalidObjectException
- The validation object is null.protected Class resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException
By default the class name is resolved relative to the class that called readObject.
v
- an instance of class ObjectStreamClassv
IOException
- Any of the usual Input/Output exceptions.ClassNotFoundException
- If class of
a serialized object cannot be found.protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException
This method is called exactly once for each unique proxy class descriptor in the stream.
The corresponding method in ObjectOutputStream
is
annotateProxyClass
. For a given subclass of
ObjectInputStream
that overrides this method, the
annotateProxyClass
method in the corresponding
subclass of ObjectOutputStream
must write any data or
objects read by this method.
The default implementation of this method in
ObjectInputStream
returns the result of calling
Proxy.getProxyClass
with the list of
Class
objects for the interfaces that are named in
the interfaces
parameter. The Class
object for each interface name i
is the value
returned by calling
Class.forName(i, false, loader)where
loader
is that of the first non-null class
loader up the execution stack, or null
if no non-null
class loaders are on the stack (the same class loader choice used
by the resolveClass
method). This same value of
loader
is also the class loader passed to
Proxy.getProxyClass
. If Proxy.getProxyClass
throws an IllegalArgumentException
,
resolveProxyClass
will throw a
ClassNotFoundException
containing the
IllegalArgumentException
.interfaces
- the list of interface names that were
deserialized in the proxy class descriptorIOException
- any exception thrown by the underlying
InputStream
ClassNotFoundException
- if the proxy class or any of the
named interfaces could not be foundObjectOutputStream.annotateProxyClass(Class)
protected Object resolveObject(Object obj) throws IOException
This method is called after an object has been read but before it is returned from readObject. The default resolveObject method just returns the same object.
When a subclass is replacing objects it must insure that the substituted object is compatible with every field where the reference will be stored. Objects whose type is not a subclass of the type of the field or array element abort the serialization by raising an exception and the object is not be stored.
This method is called only once when each object is first encountered. All subsequent references to the object will be redirected to the new object.
obj
- object to be substitutedIOException
- Any of the usual Input/Output exceptions.protected boolean enableResolveObject(boolean enable) throws SecurityException
checkPermission
method with the
SerializablePermission("enableSubstitution")
permission to ensure it's ok to
enable the stream to allow objects read from the stream to be replaced.enable
- true for enabling use of resolveObject
for
every object being deserializedSecurityException
- if a security manager exists and its
checkPermission
method denies
enabling the stream to allow objects read from the stream to be
replaced.SecurityManager.checkPermission(java.security.Permission)
,
SerializablePermission
protected void readStreamHeader() throws IOException, StreamCorruptedException
IOException
- if there are I/O errors while reading from the
underlying InputStream
StreamCorruptedException
- if control information in the
stream is inconsistentprotected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException
writeClassDescriptor
method). By default,
this method reads class descriptors according to the format defined in
the Object Serialization specification.
IOException
- If an I/O error has occurred.ClassNotFoundException
- If the Class of a serialized object
used in the class descriptor representation cannot be foundObjectOutputStream.writeClassDescriptor(java.io.ObjectStreamClass)
public int read() throws IOException
read
in interface ObjectInput
read
in class InputStream
IOException
- If an I/O error has occurred.public int read(byte[] b, int off, int len) throws IOException
read
in interface ObjectInput
read
in class InputStream
b
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes readIOException
- If an I/O error has occurred.DataInputStream.readFully(byte[],int,int)
public int available() throws IOException
available
in interface ObjectInput
available
in class InputStream
IOException
- if there are I/O errors while reading from the
underlying InputStream
public void close() throws IOException
close
in interface ObjectInput
close
in class InputStream
IOException
- If an I/O error has occurred.public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public byte readByte() throws IOException
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public short readShort() throws IOException
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public char readChar() throws IOException
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public int readInt() throws IOException
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public long readLong() throws IOException
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public float readFloat() throws IOException
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public double readDouble() throws IOException
readDouble
in interface DataInput
EOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public void readFully(byte[] data) throws IOException
data
- the buffer into which the data is readEOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public void readFully(byte[] data, int offset, int size) throws IOException
data
- the buffer into which the data is readoffset
- the start offset of the datasize
- the maximum number of bytes to readEOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public int skipBytes(int len) throws IOException
len
- the number of bytes to be skippedEOFException
- If end of file is reached.IOException
- If other I/O error has occurred.public String readLine() throws IOException
IOException
- if there are I/O errors while reading from the
underlying InputStream
public String readUTF() throws IOException
IOException
- if there are I/O errors while reading from the
underlying InputStream
|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.