|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.InputStream | +--java.io.ObjectInputStream
Untamed:
Field Summary | |
private java.io.ObjectInputStream.BlockDataInputStream |
bin
filter stream for handling block data conversion |
private boolean |
closed
whether stream is closed |
private ObjectStreamClass |
curDesc
descriptor for current class (null if in readExternal()) |
private java.io.ObjectInputStream.GetFieldImpl |
curGet
current GetField object |
private Object |
curObj
object currently being deserialized |
private boolean |
defaultDataEnd
flag set when at end of field value block with no TC_ENDBLOCKDATA |
private int |
depth
recursion depth |
private boolean |
enableOverride
if true, invoke readObjectOverride() instead of readObject() |
private boolean |
enableResolve
if true, invoke resolveObject() |
private java.io.ObjectInputStream.HandleTable |
handles
wire handle -> obj/exception map |
private static int |
NULL_HANDLE
handle value representing null |
private int |
passHandle
scratch field for passing handle values up/down call stack |
private static HashMap |
primClasses
table mapping primitive type names to corresponding class objects |
private byte[] |
primVals
buffer for reading primitive field values |
private static sun.misc.SoftCache |
subclassAudits
cache of subclass security audit results |
private static Object |
unsharedMarker
marker for unshared objects in internal handle table |
private java.io.ObjectInputStream.ValidationList |
vlist
validation callback list |
Fields inherited from class java.io.InputStream |
|
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)
Enabled: Creates an ObjectInputStream that reads from the specified InputStream. |
Method Summary | |
private static boolean |
auditSubclass(Class subcl)
Performs reflective checks on given subclass to verify that it doesn't override security-sensitive non-final methods. |
int |
available()
Enabled: Returns the number of bytes that can be read without blocking. |
private static void |
bytesToDoubles(byte[] src,
int srcpos,
double[] dst,
int dstpos,
int ndoubles)
Converts specified span of bytes into double values. |
private static void |
bytesToFloats(byte[] src,
int srcpos,
float[] dst,
int dstpos,
int nfloats)
Converts specified span of bytes into float values. |
private Object |
checkResolve(Object obj)
If resolveObject has been enabled and given object does not have an exception associated with it, calls resolveObject to determine replacement for object, and updates handle table accordingly. |
private void |
clear()
Clears internal data structures. |
void |
close()
Enabled: Closes the input stream. |
private void |
defaultReadFields(Object obj,
ObjectStreamClass desc)
Reads in values of serializable fields declared by given class descriptor. |
void |
defaultReadObject()
Enabled: 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. |
private void |
handleReset()
If recursion depth is 0, clears internal data structures; otherwise, throws a StreamCorruptedException. |
private static ClassLoader |
latestUserDefinedLoader()
Returns the first non-null class loader (not counting class loaders of generated reflection implementation classes) up the execution stack, or null if only code from the null class loader is on the stack. |
int |
read()
Enabled: Reads a byte of data. |
int |
read(byte[] buf,
int off,
int len)
Enabled: Reads into an array of bytes. |
private Object |
readArray(boolean unshared)
Reads in and returns array object, or null if array class is unresolvable. |
boolean |
readBoolean()
Enabled: Reads in a boolean. |
byte |
readByte()
Enabled: Reads an 8 bit byte. |
char |
readChar()
Enabled: Reads a 16 bit char. |
private Class |
readClass(boolean unshared)
Reads in and returns class object. |
private ObjectStreamClass |
readClassDesc(boolean unshared)
Reads in and returns (possibly null) class descriptor. |
protected ObjectStreamClass |
readClassDescriptor()
Read a class descriptor from the serialization stream. |
double |
readDouble()
Enabled: Reads a 64 bit double. |
private void |
readExternalData(Externalizable obj,
ObjectStreamClass desc)
If obj is non-null, reads externalizable data by invoking readExternal() method of obj; otherwise, attempts to skip over externalizable data. |
private IOException |
readFatalException()
Reads in and returns IOException that caused serialization to abort. |
java.io.ObjectInputStream.GetField |
readFields()
Enabled: Reads the persistent fields from the stream and makes them available by name. |
float |
readFloat()
Enabled: Reads a 32 bit float. |
void |
readFully(byte[] buf)
Enabled: Reads bytes, blocking until all bytes are read. |
void |
readFully(byte[] buf,
int off,
int len)
Enabled: Reads bytes, blocking until all bytes are read. |
private Object |
readHandle(boolean unshared)
Reads in object handle, sets passHandle to the read handle, and returns object associated with the handle. |
int |
readInt()
Enabled: 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()
Enabled: Reads a 64 bit long. |
private ObjectStreamClass |
readNonProxyDesc(boolean unshared)
Reads in and returns class descriptor for a class that is not a dynamic proxy class. |
private Object |
readNull()
Reads in null code, sets passHandle to NULL_HANDLE and returns null. |
Object |
readObject()
Enabled: Read an object from the ObjectInputStream. |
private Object |
readObject0(boolean unshared)
Underlying readObject implementation. |
protected Object |
readObjectOverride()
This method is called by trusted subclasses of ObjectOutputStream that constructed ObjectOutputStream using the protected no-arg constructor. |
private Object |
readOrdinaryObject(boolean unshared)
Reads and returns "ordinary" (i.e., not a String, Class, ObjectStreamClass or array) object, or null if object's class is unresolvable (in which case a ClassNotFoundException will be associated with object's handle). |
private ObjectStreamClass |
readProxyDesc(boolean unshared)
Reads in and returns class descriptor for a dynamic proxy class. |
private void |
readSerialData(Object obj,
ObjectStreamClass desc)
Reads (or attempts to skip, if obj is null or is tagged with a ClassNotFoundException) instance data for each serializable class of object in stream, from superclass to subclass. |
short |
readShort()
Enabled: Reads a 16 bit short. |
protected void |
readStreamHeader()
The readStreamHeader method is provided to allow subclasses to read and verify their own stream headers. |
private String |
readString(boolean unshared)
Reads in and returns new string. |
(package private) String |
readTypeString()
Reads string without allowing it to be replaced in stream. |
Object |
readUnshared()
Enabled: Reads an "unshared" object from the ObjectInputStream. |
int |
readUnsignedByte()
Enabled: Reads an unsigned 8 bit byte. |
int |
readUnsignedShort()
Enabled: Reads an unsigned 16 bit short. |
String |
readUTF()
Enabled: Reads a UTF format String. |
void |
registerValidation(ObjectInputValidation obj,
int prio)
Enabled: Register an object to be validated before the graph is returned. |
protected Class |
resolveClass(ObjectStreamClass desc)
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)
Enabled: Skips bytes, block until all bytes are skipped. |
private void |
skipCustomData()
Skips over all block data and objects until TC_ENDBLOCKDATA is encountered. |
private void |
verifySubclass()
Verifies that this (possibly subclass) instance can be constructed without violating security constraints: the subclass must not override security-sensitive non-final methods, or else the "enableSubclassImplementation" SerializablePermission is checked. |
Methods inherited from class java.io.InputStream |
__printOn, getCryptoHash, mark, markSupported, read, readAvailable, 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 |
Methods inherited from interface java.io.DataInput |
readWholeNum |
Field Detail |
private static final int NULL_HANDLE
private static final Object unsharedMarker
private static final HashMap primClasses
private static final sun.misc.SoftCache subclassAudits
private final java.io.ObjectInputStream.BlockDataInputStream bin
private final java.io.ObjectInputStream.ValidationList vlist
private int depth
private boolean closed
private final java.io.ObjectInputStream.HandleTable handles
private int passHandle
private boolean defaultDataEnd
private byte[] primVals
private final boolean enableOverride
private boolean enableResolve
private Object curObj
private ObjectStreamClass curDesc
private java.io.ObjectInputStream.GetFieldImpl curGet
Constructor Detail |
public ObjectInputStream(InputStream in) throws IOException
If a security manager is installed, this constructor will check for the "enableSubclassImplementation" SerializablePermission when invoked directly or indirectly by the constructor of a subclass which overrides the ObjectInputStream.readFields or ObjectInputStream.readUnshared methods.
in
- input stream to read from
StreamCorruptedException
- if the stream header is incorrect
IOException
- if an I/O error occurs while reading stream header
SecurityException
- if untrusted subclass illegally overrides
security-sensitive methods
NullPointerException
- if in
is null
ObjectInputStream()
,
readFields()
,
ObjectOutputStream.ObjectOutputStream(OutputStream)
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.
SecurityException
- if a security manager exists and its
checkPermission
method denies enabling
subclassing.
IOException
SecurityManager.checkPermission(java.security.Permission)
,
java.io.SerializablePermission
Method Detail |
public final Object readObject() throws IOException, ClassNotFoundException
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 IOException, ClassNotFoundException
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 Object readUnshared() throws IOException, ClassNotFoundException
However, for objects which are not instances of java.lang.Class and do not define readResolve methods, readUnshared guarantees that the returned object reference is unique and cannot be obtained a second time from the ObjectInputStream that created it, even if the underlying data stream has been manipulated. This guarantee applies only to the base-level object returned by readUnshared, and not to any transitively referenced sub-objects in the returned object graph.
ObjectInputStream subclasses which override this method can only be constructed in security contexts possessing the "enableSubclassImplementation" SerializablePermission; any attempt to instantiate such a subclass without this permission will cause a SecurityException to be thrown.
ClassNotFoundException
- if class of an object to deserialize
cannot be found
StreamCorruptedException
- if control information in the stream
is inconsistent
ObjectStreamException
- if object to deserialize has already
appeared in stream
OptionalDataException
- if primitive data is next in stream
IOException
- if an I/O error occurs during deserializationpublic void defaultReadObject() throws IOException, ClassNotFoundException
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 java.io.ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException
GetField
object representing the persistent
fields of the object being deserialized
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 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 desc) throws IOException, ClassNotFoundException
The corresponding method in ObjectOutputStream
is
annotateClass
. This method will be invoked only once for
each unique class in the stream. This method can be implemented by
subclasses to use an alternate loading mechanism but must return a
Class
object. Once returned, the serialVersionUID of the
class is compared to the serialVersionUID of the serialized class. If
there is a mismatch, the deserialization fails and an exception is
raised.
By default the class name is resolved relative to the class that
called readObject
.
desc
- an instance of class ObjectStreamClass
Class
object corresponding to desc
IOException
- any of the usual input/output exceptions
ClassNotFoundException
- if class of a serialized object cannot
be foundprotected 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). Unless any
of the resolved interfaces are non-public, this same value of
loader
is also the class loader passed to
Proxy.getProxyClass
; if non-public interfaces are present,
their class loader is passed instead (if more than one non-public
interface class loader is encountered, an
IllegalAccessError
is thrown).
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 descriptor
IOException
- 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 substituted
IOException
- Any of the usual Input/Output exceptions.protected boolean enableResolveObject(boolean enable) throws SecurityException
If enable is true, and there is a security manager installed,
this method first calls the security manager's
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 deserialized
SecurityException
- 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)
,
java.io.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 foundjava.io.ObjectOutputStream#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[] buf, int off, int len) throws IOException
read
in interface ObjectInput
read
in class InputStream
buf
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes read
IOException
- If an I/O error has occurred.java.io.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
readByte
in interface DataInput
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 char readChar() throws IOException
readChar
in interface DataInput
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public short readShort() throws IOException
readShort
in interface DataInput
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 int readInt() throws IOException
readInt
in interface DataInput
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public long readLong() throws IOException
readLong
in interface DataInput
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public float readFloat() throws IOException
readFloat
in interface DataInput
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[] buf) throws IOException
readFully
in interface DataInput
buf
- the buffer into which the data is read
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public void readFully(byte[] buf, int off, int len) throws IOException
readFully
in interface DataInput
buf
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes to read
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public int skipBytes(int len) throws IOException
skipBytes
in interface DataInput
len
- the number of bytes to be skipped
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public String readLine() throws IOException
readLine
in interface DataInput
IOException
- if there are I/O errors while reading from the
underlying InputStream
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
- if there are I/O errors while reading from the
underlying InputStream
UTFDataFormatException
- if read bytes do not represent a valid
UTF-8 encoding of a stringprivate void verifySubclass()
private static boolean auditSubclass(Class subcl)
private void clear()
private Object readObject0(boolean unshared) throws IOException
IOException
private Object checkResolve(Object obj) throws IOException
IOException
String readTypeString() throws IOException
IOException
private Object readNull() throws IOException
IOException
private Object readHandle(boolean unshared) throws IOException
IOException
private Class readClass(boolean unshared) throws IOException
IOException
private ObjectStreamClass readClassDesc(boolean unshared) throws IOException
IOException
private ObjectStreamClass readProxyDesc(boolean unshared) throws IOException
IOException
private ObjectStreamClass readNonProxyDesc(boolean unshared) throws IOException
IOException
private String readString(boolean unshared) throws IOException
IOException
private Object readArray(boolean unshared) throws IOException
IOException
private Object readOrdinaryObject(boolean unshared) throws IOException
IOException
private void readExternalData(Externalizable obj, ObjectStreamClass desc) throws IOException
IOException
private void readSerialData(Object obj, ObjectStreamClass desc) throws IOException
IOException
private void skipCustomData() throws IOException
IOException
private void defaultReadFields(Object obj, ObjectStreamClass desc) throws IOException
IOException
private IOException readFatalException() throws IOException
IOException
private void handleReset() throws StreamCorruptedException
StreamCorruptedException
private static void bytesToFloats(byte[] src, int srcpos, float[] dst, int dstpos, int nfloats)
private static void bytesToDoubles(byte[] src, int srcpos, double[] dst, int dstpos, int ndoubles)
private static ClassLoader latestUserDefinedLoader()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |