|
Marshalling API version 1.0.0.Beta2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.ObjectInputStream
org.jboss.marshalling.MarshallerObjectInputStream
public abstract class MarshallerObjectInputStream
A marshaller's object input stream. Used by marshallers for compatibility with Java serialization. Instances of
this class may be passed in to the overriden serialization methods for a class implementing Serializable
.
This class is not part of the marshalling API; rather it is intended for marshaller implementors to make it easier to develop Java serialization-compatible marshallers.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.io.ObjectInputStream |
---|
ObjectInputStream.GetField |
Field Summary |
---|
Constructor Summary | |
---|---|
protected |
MarshallerObjectInputStream(Unmarshaller input)
Construct a new instance which delegates to the given unmarshaller. |
Method Summary | |
---|---|
int |
available()
Returns the number of bytes that can be read without blocking. |
void |
close()
Closes the input stream. |
abstract 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. |
void |
mark(int readlimit)
Marks the current position in this input stream. |
boolean |
markSupported()
Tests if this input stream supports the mark and
reset methods. |
int |
read()
Reads a byte of data. |
int |
read(byte[] buf)
Reads some number of bytes from the input stream and stores them into the buffer array b . |
int |
read(byte[] buf,
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. |
abstract 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[] buf)
Reads bytes, blocking until all bytes are read. |
void |
readFully(byte[] buf,
int off,
int len)
Reads bytes, blocking until all bytes are read. |
int |
readInt()
Reads a 32 bit int. |
String |
readLine()
Deprecated. |
long |
readLong()
Reads a 64 bit long. |
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. |
Object |
readUnshared()
Reads an "unshared" object from the ObjectInputStream. |
int |
readUnsignedByte()
Reads an unsigned 8 bit byte. |
int |
readUnsignedShort()
Reads an unsigned 16 bit short. |
String |
readUTF()
Reads a String in modified UTF-8 format. |
abstract void |
registerValidation(ObjectInputValidation obj,
int prio)
Register an object to be validated before the graph is returned. |
void |
reset()
Repositions this stream to the position at the time the mark method was last called on this input stream. |
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. |
long |
skip(long n)
Skips over and discards n bytes of data from this input
stream. |
int |
skipBytes(int len)
Skips bytes. |
Methods inherited from class java.io.ObjectInputStream |
---|
readObject |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected MarshallerObjectInputStream(Unmarshaller input) throws IOException, SecurityException
input
- the delegate unmarshaller
IOException
- if an I/O error occurs
SecurityException
- if the caller does not have permission to construct an instance of this classMethod Detail |
---|
protected Object readObjectOverride() throws IOException, ClassNotFoundException
readObjectOverride
in class ObjectInputStream
IOException
- if I/O errors occurred while reading from the
underlying stream
ClassNotFoundException
- Class definition of a serialized object
cannot be found.ObjectInputStream.ObjectInputStream()
,
ObjectInputStream.readObject()
public Object readUnshared() throws IOException, ClassNotFoundException
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.
readUnshared
in class ObjectInputStream
StreamCorruptedException
- if control information in the stream
is inconsistent
ObjectStreamException
- if object to deserialize has already
appeared in stream
IOException
- if an I/O error occurs during deserialization
ClassNotFoundException
- if class of an object to deserialize
cannot be foundpublic int read() throws IOException
read
in interface ObjectInput
read
in class ObjectInputStream
IOException
- If an I/O error has occurred.public int read(byte[] buf) throws IOException
b
. The number of bytes actually read is
returned as an integer. This method blocks until input data is
available, end of file is detected, or an exception is thrown.
If the length of b
is zero, then no bytes are read and
0
is returned; otherwise, there is an attempt to read at
least one byte. If no byte is available because the stream is at the
end of the file, the value -1
is returned; otherwise, at
least one byte is read and stored into b
.
The first byte read is stored into element b[0]
, the
next one into b[1]
, and so on. The number of bytes read is,
at most, equal to the length of b
. Let k be the
number of bytes actually read; these bytes will be stored in elements
b[0]
through b[
k-1]
,
leaving elements b[
k]
through
b[b.length-1]
unaffected.
The read(b)
method for class InputStream
has the same effect as:
read(b, 0, b.length)
read
in interface ObjectInput
read
in class InputStream
buf
- the buffer into which the data is read.
-1
is there is no more data because the end of
the stream has been reached.
IOException
- If the first byte cannot be read for any reason
other than the end of the file, if the input stream has been closed, or
if some other I/O error occurs.InputStream.read(byte[], int, int)
public int read(byte[] buf, int off, int len) throws IOException
read
in interface ObjectInput
read
in class ObjectInputStream
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.DataInputStream.readFully(byte[],int,int)
public int available() throws IOException
available
in interface ObjectInput
available
in class ObjectInputStream
IOException
- if there are I/O errors while reading from the
underlying InputStream
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
readBoolean
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public byte readByte() throws IOException
readByte
in interface DataInput
readByte
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
readUnsignedByte
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public char readChar() throws IOException
readChar
in interface DataInput
readChar
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public short readShort() throws IOException
readShort
in interface DataInput
readShort
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
readUnsignedShort
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public int readInt() throws IOException
readInt
in interface DataInput
readInt
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public long readLong() throws IOException
readLong
in interface DataInput
readLong
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public float readFloat() throws IOException
readFloat
in interface DataInput
readFloat
in class ObjectInputStream
EOFException
- If end of file is reached.
IOException
- If other I/O error has occurred.public double readDouble() throws IOException
readDouble
in interface DataInput
readDouble
in class ObjectInputStream
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
readFully
in class ObjectInputStream
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
readFully
in class ObjectInputStream
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
skipBytes
in class ObjectInputStream
len
- the number of bytes to be skipped
IOException
- If an I/O error has occurred.@Deprecated public String readLine() throws IOException
readLine
in interface DataInput
readLine
in class ObjectInputStream
IOException
- if there are I/O errors while reading from the
underlying InputStream
public String readUTF() throws IOException
readUTF
in interface DataInput
readUTF
in class ObjectInputStream
IOException
- if there are I/O errors while reading from the
underlying InputStream
UTFDataFormatException
- if read bytes do not represent a valid
modified UTF-8 encoding of a stringpublic long skip(long n) throws IOException
n
bytes of data from this input
stream. The skip
method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0
.
This may result from any of a number of conditions; reaching end of file
before n
bytes have been skipped is only one possibility.
The actual number of bytes skipped is returned. If n
is
negative, no bytes are skipped.
The skip
method of this class creates a
byte array and then repeatedly reads into it until n
bytes
have been read or the end of the stream has been reached. Subclasses are
encouraged to provide a more efficient implementation of this method.
For instance, the implementation may depend on the ability to seek.
skip
in interface ObjectInput
skip
in class InputStream
n
- the number of bytes to be skipped.
IOException
- if the stream does not support seek,
or if some other I/O error occurs.public final void mark(int readlimit)
reset
method repositions this stream at the last marked
position so that subsequent reads re-read the same bytes.
The readlimit
arguments tells this input stream to
allow that many bytes to be read before the mark position gets
invalidated.
The general contract of mark
is that, if the method
markSupported
returns true
, the stream somehow
remembers all the bytes read after the call to mark
and
stands ready to supply those same bytes again if and whenever the method
reset
is called. However, the stream is not required to
remember any data at all if more than readlimit
bytes are
read from the stream before reset
is called.
Marking a closed stream should not have any effect on the stream.
The mark
method of InputStream
does
nothing.
mark
in class InputStream
readlimit
- the maximum limit of bytes that can be read before
the mark position becomes invalid.InputStream.reset()
public final void reset() throws IOException
mark
method was last called on this input stream.
The general contract of reset
is:
markSupported
returns
true
, then:
mark
has not been called since
the stream was created, or the number of bytes read from the stream
since mark
was last called is larger than the argument
to mark
at that last call, then an
IOException
might be thrown.
IOException
is not thrown, then the
stream is reset to a state such that all the bytes read since the
most recent call to mark
(or since the start of the
file, if mark
has not been called) will be resupplied
to subsequent callers of the read
method, followed by
any bytes that otherwise would have been the next input data as of
the time of the call to reset
. markSupported
returns
false
, then:
reset
may throw an
IOException
.
IOException
is not thrown, then the stream
is reset to a fixed state that depends on the particular type of the
input stream and how it was created. The bytes that will be supplied
to subsequent callers of the read
method depend on the
particular type of the input stream. The method reset
for class InputStream
does nothing except throw an IOException
.
reset
in class InputStream
IOException
- if this stream has not been marked or if the
mark has been invalidated.InputStream.mark(int)
,
IOException
public final boolean markSupported()
mark
and
reset
methods. Whether or not mark
and
reset
are supported is an invariant property of a
particular input stream instance. The markSupported
method
of InputStream
returns false
.
markSupported
in class InputStream
true
if this stream instance supports the mark
and reset methods; false
otherwise.InputStream.mark(int)
,
InputStream.reset()
public final void close() throws IllegalStateException
close
in interface Closeable
close
in interface ObjectInput
close
in class ObjectInputStream
IllegalStateException
protected final Class<?> resolveClass(ObjectStreamClass desc) throws IllegalStateException
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, if the class is not an array
class, its serialVersionUID is compared to the serialVersionUID of the
serialized class, and if there is a mismatch, the deserialization fails
and an InvalidClassException
is thrown.
The default implementation of this method in
ObjectInputStream
returns the result of calling
Class.forName(desc.getName(), false, loader)where
loader
is determined as follows: if there is a
method on the current thread's stack whose declaring class was
defined by a user-defined class loader (and was not a generated to
implement reflective invocations), then loader
is class
loader corresponding to the closest such method to the currently
executing frame; otherwise, loader
is
null
. If this call results in a
ClassNotFoundException
and the name of the passed
ObjectStreamClass
instance is the Java language keyword
for a primitive type or void, then the Class
object
representing that primitive type or void will be returned
(e.g., an ObjectStreamClass
with the name
"int"
will be resolved to Integer.TYPE
).
Otherwise, the ClassNotFoundException
will be thrown to
the caller of this method.
resolveClass
in class ObjectInputStream
desc
- an instance of class ObjectStreamClass
Class
object corresponding to desc
IllegalStateException
protected final Class<?> resolveProxyClass(String[] interfaces) throws IllegalStateException
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
.
resolveProxyClass
in class ObjectInputStream
interfaces
- the list of interface names that were
deserialized in the proxy class descriptor
IllegalStateException
ObjectOutputStream.annotateProxyClass(Class)
protected final Object resolveObject(Object obj) throws IllegalStateException
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.
resolveObject
in class ObjectInputStream
obj
- object to be substituted
IllegalStateException
protected final boolean enableResolveObject(boolean enable) throws IllegalStateException
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.
enableResolveObject
in class ObjectInputStream
enable
- true for enabling use of resolveObject
for
every object being deserialized
IllegalStateException
SecurityManager.checkPermission(java.security.Permission)
,
SerializablePermission
protected final void readStreamHeader() throws IllegalStateException
readStreamHeader
in class ObjectInputStream
IllegalStateException
protected final ObjectStreamClass readClassDescriptor() throws IllegalStateException
writeClassDescriptor
method). By default,
this method reads class descriptors according to the format defined in
the Object Serialization specification.
readClassDescriptor
in class ObjectInputStream
IllegalStateException
ObjectOutputStream.writeClassDescriptor(java.io.ObjectStreamClass)
public abstract void defaultReadObject() throws IOException, ClassNotFoundException
defaultReadObject
in class ObjectInputStream
IOException
- if an I/O error occurs.
NotActiveException
- if the stream is not currently reading
objects.
ClassNotFoundException
- if the class of a serialized object
could not be found.public abstract ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException
readFields
in class ObjectInputStream
GetField
object representing the persistent
fields of the object being deserialized
IOException
- if an I/O error occurs.
NotActiveException
- if the stream is not currently reading
objects.
ClassNotFoundException
- if the class of a serialized object
could not be found.public abstract void registerValidation(ObjectInputValidation obj, int prio) throws NotActiveException, InvalidObjectException
registerValidation
in class ObjectInputStream
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.
|
Marshalling API version 1.0.0.Beta2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |