public class AtomicMarshalInputStream extends MarshalInputStream
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
Externalizable
Serializable object's with a public zero arg constructor,
with serial forms that contain only primitive fields, any object fields must
be marked transient.Entry, stream data will be checked against
each field type.
Any of the above classes that have the appropriate DeSerializationPermission,
Serializable object's that have only primitive serial form, don't
require DeSerializationPermission.
The Serialization stream protocol.
Collection, List Set, SortedSet, Map and SortedMap, are replaced in AtomicObjectOutputStream with immutable implementations that guard against denial of service attacks. These collections are not intended to be used in de-serialized form, other than for passing as an argument to create a new collection. Collections should be type checked during validation before a superclass constructor is called.
AtomicMarshalInputStream is restricted to caching 2^16 objects, and a total combined array length of Integer.MAX_VALUE - 8, for all arrays, the stream must be reset prior to exceeding these limits or a StreamCorruptedException will be thrown and control will return to the caller.
JVM arguments should be adjusted to ensure that an OOME will not be thrown if these limits are reached.
ObjectInputStream.GetFieldbaseWireHandle, 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| Constructor and Description |
|---|
AtomicMarshalInputStream(InputStream input,
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader,
Collection context)
Constructs a new ObjectInputStream that reads from the InputStream
input. |
AtomicMarshalInputStream(InputStream input,
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader,
Collection context,
boolean readAnnotations)
Constructs a new ObjectInputStream that reads from the InputStream
input. |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes of primitive data that can be read from this
stream without blocking.
|
void |
close()
Closes this stream.
|
static ObjectInputStream |
create(InputStream in,
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader,
Collection context,
boolean readAnnotations)
The instance returned can de-serialize data written by
ObjectOutputStream when readAnnotations is false, it is compatible
with MarshalOutputStream when readAnnotations is true. |
void |
defaultReadObject()
Default method to read objects from this stream.
|
protected boolean |
enableResolveObject(boolean enable)
Enables object replacement for this stream.
|
int |
read()
Reads a single byte from the source stream and returns it as an integer
in the range from 0 to 255.
|
int |
read(byte[] buffer,
int offset,
int length)
Reads at most
length bytes from the source stream and stores them
in byte array buffer starting at offset count. |
protected String |
readAnnotation()
Reads and returns a class annotation string value (possibly
null) that was written by a corresponding
MarshalOutputStream implementation. |
boolean |
readBoolean()
Reads a boolean from the source stream.
|
byte |
readByte()
Reads a byte (8 bit) from the source stream.
|
char |
readChar()
Reads a character (16 bit) from the source stream.
|
protected ObjectStreamClass |
readClassDescriptor()
Reads a class descriptor from the source stream.
|
double |
readDouble()
Reads a double (64 bit) from the source stream.
|
ObjectInputStream.GetField |
readFields()
Reads the persistent fields of the object that is currently being read
from the source stream.
|
float |
readFloat()
Reads a float (32 bit) from the source stream.
|
void |
readFully(byte[] buffer)
Reads bytes from the source stream into the byte array
buffer. |
void |
readFully(byte[] buffer,
int offset,
int length)
Reads bytes from the source stream into the byte array
buffer. |
int |
readInt()
Reads an integer (32 bit) from the source stream.
|
String |
readLine()
Deprecated.
Use
BufferedReader |
long |
readLong()
Reads a long (64 bit) from the source stream.
|
<T> T |
readObject(Class<T> type)
Reads the tc object from the source stream.
|
protected Object |
readObjectOverride()
Reads the tc object from the source stream.
|
short |
readShort()
Reads a short (16 bit) from the source stream.
|
protected void |
readStreamHeader()
Does nothing.
|
Object |
readUnshared()
Reads the tc unshared object from the source stream.
|
<T> T |
readUnshared(Class<T> type)
Reads the tc unshared object from the source stream.
|
int |
readUnsignedByte()
Reads an unsigned byte (8 bit) from the source stream.
|
int |
readUnsignedShort()
Reads an unsigned short (16 bit) from the source stream.
|
String |
readUTF()
Reads a string encoded in
modified UTF-8 from the
source stream. |
void |
registerValidation(ObjectInputValidation object,
int priority)
Registers a callback for post-deserialization validation of objects.
|
protected Class |
replaceClass(Class c) |
protected Object |
replaceObject(Object o) |
int |
skipBytes(int length)
Skips
length bytes on the source stream. |
getDefaultClassLoader, getObjectStreamContext, getVerifierClassLoader, resolveClass, resolveProxyClass, useCodebaseAnnotationsreadObject, resolveObjectmark, markSupported, read, reset, skipclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitread, skippublic AtomicMarshalInputStream(InputStream input, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException
input.input - the non-null source InputStream to filter reads on.defaultLoader - verifyCodebaseIntegrity - verifierLoader - context - IOException - if an error occurs while reading the stream header.StreamCorruptedException - if the source stream does not contain serialized objects that
can be read.SecurityException - if a security manager is installed and it denies subclassing
this class.public AtomicMarshalInputStream(InputStream input, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context, boolean readAnnotations) throws IOException
input.input - the non-null source InputStream to filter reads on.defaultLoader - verifyCodebaseIntegrity - verifierLoader - context - readAnnotations - if false is generally compatible with ObjectInputStream
otherwise, if true is generally compatible with MarshalInputStreamIOException - if an error occurs while reading the stream header.StreamCorruptedException - if the source stream does not contain serialized objects that
can be read.SecurityException - if a security manager is installed and it denies subclassing
this class.public static ObjectInputStream create(InputStream in, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context, boolean readAnnotations) throws IOException
ObjectOutputStream when readAnnotations is false, it is compatible
with MarshalOutputStream when readAnnotations is true.in - defaultLoader - verifyCodebaseIntegrity - verifierLoader - context - readAnnotations - if true, annotations will be read by the stream, note
this does not determine whether the annotation will be used, only whether
it's read from the stream or not.IOExceptionpublic int available()
throws IOException
available in interface ObjectInputavailable in class ObjectInputStreamIOException - if any I/O problem occurs while computing the available
bytes.public void close()
throws IOException
close in interface Closeableclose in interface ObjectInputclose in interface AutoCloseableclose in class ObjectInputStreamIOException - if an error occurs while closing this stream.public void defaultReadObject()
throws IOException,
ClassNotFoundException,
NotActiveException
defaultReadObject in class ObjectInputStreamClassNotFoundException - if the object's class cannot be found.IOException - if an I/O error occurs while reading the object data.NotActiveException - if this method is not called from readObject().ObjectOutputStream.defaultWriteObject()protected boolean enableResolveObject(boolean enable)
throws SecurityException
enableResolveObject in class ObjectInputStreamenable - true to enable object replacement; false to
disable it.SecurityException - if a security manager is installed and it denies enabling
object replacement for this stream.ObjectInputStream.resolveObject(java.lang.Object),
ObjectOutputStream.enableReplaceObject(boolean)public int read()
throws IOException
read in interface ObjectInputread in class ObjectInputStreamIOException - if an error occurs while reading from this stream.public int read(byte[] buffer,
int offset,
int length)
throws IOException
length bytes from the source stream and stores them
in byte array buffer starting at offset count. Blocks
until count bytes have been read, the end of the source stream is
detected or an exception is thrown.read in interface ObjectInputread in class ObjectInputStreambuffer - the array in which to store the bytes read.offset - the initial position in buffer to store the bytes
read from the source stream.length - the maximum number of bytes to store in buffer.IndexOutOfBoundsException - if offset < 0 or length < 0, or if
offset + length is greater than the length of
buffer.IOException - if an error occurs while reading from this stream.NullPointerException - if buffer is null.protected String readAnnotation() throws IOException, ClassNotFoundException
MarshalInputStreamnull) that was written by a corresponding
MarshalOutputStream implementation.
MarshalInputStream implements this method to
just read the annotation value from this stream using readObject, and if
readObject returns a non-null value
that is not a String, an InvalidObjectException is thrown.
A subclass can override this method to read the annotation from a different location.
readAnnotation in class MarshalInputStreamnull)IOException - if an I/O exception occurs reading the
annotationClassNotFoundException - if a
ClassNotFoundException occurs reading the
annotationpublic boolean readBoolean()
throws IOException
readBoolean in interface DataInputreadBoolean in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public byte readByte()
throws IOException
readByte in interface DataInputreadByte in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public char readChar()
throws IOException
readChar in interface DataInputreadChar in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public double readDouble()
throws IOException
readDouble in interface DataInputreadDouble in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException, NotActiveException
readFields in class ObjectInputStreamClassNotFoundException - if the class of an object being deserialized can not be
found.IOException - if an error occurs while reading from this stream.NotActiveException - if this stream is currently not reading an object.public float readFloat()
throws IOException
readFloat in interface DataInputreadFloat in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public void readFully(byte[] buffer)
throws IOException
buffer.
This method will block until buffer.length bytes have been read.readFully in interface DataInputreadFully in class ObjectInputStreambuffer - the array in which to store the bytes read.EOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public void readFully(byte[] buffer,
int offset,
int length)
throws IOException
buffer.
This method will block until length number of bytes have been
read.readFully in interface DataInputreadFully in class ObjectInputStreambuffer - the byte array in which to store the bytes read.offset - the initial position in buffer to store the bytes
read from the source stream.length - the maximum number of bytes to store in buffer.EOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public int readInt()
throws IOException
readInt in interface DataInputreadInt in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.@Deprecated public String readLine() throws IOException
BufferedReader'\r', '\n', "\r\n" or an EOF.readLine in interface DataInputreadLine in class ObjectInputStreamIOException - if an error occurs while reading from the source stream.public long readLong()
throws IOException
readLong in interface DataInputreadLong in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.protected final ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException
readClassDescriptor in class ObjectInputStreamClassNotFoundException - if a class for one of the objects cannot be found.IOException - if an error occurs while reading from the source stream.protected Object replaceObject(Object o) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionprotected final Object readObjectOverride() throws OptionalDataException, ClassNotFoundException, IOException
readObjectOverride in class ObjectInputStreamClassNotFoundException - if the class of one of the objects in the object graph cannot
be found.IOException - if an error occurs while reading from the source stream.OptionalDataException - if primitive data types were found instead of an object.OptionalDataExceptionObjectOutputStream.writeObject(Object)public <T> T readObject(Class<T> type) throws IOException, ClassNotFoundException
Reads the tc object from the source stream. In this case, the Object will only be read from the stream if the type matches.
If the stream type doesn't match, AtomicMarshalInputStream will check if the class has a readResolve method and check its annotated with @Serializer with a declared return type. If neither match the expected type, an InvalidObjectException will be thrown.
If no exception is thrown, then AtomicMarshalInputStream will proceed and deserialize the object.
T - type - ClassNotFoundException - if the class of one of the objects in the object graph cannot
be found.IOException - if an error occurs while reading from the source stream.ObjectOutputStream.writeUnshared(java.lang.Object)public Object readUnshared() throws IOException, ClassNotFoundException
readUnshared in class ObjectInputStreamClassNotFoundException - if the class of one of the objects in the object graph cannot
be found.IOException - if an error occurs while reading from the source stream.ObjectOutputStream.writeUnshared(java.lang.Object)public <T> T readUnshared(Class<T> type) throws IOException, ClassNotFoundException
type - the Class of the object to be read.ClassNotFoundException - if the class of one of the objects in the object graph cannot
be found.IOException - if an error occurs while reading from the source stream.ObjectOutputStream.writeUnshared(java.lang.Object)public short readShort()
throws IOException
readShort in interface DataInputreadShort in class ObjectInputStreamIOException - if an error occurs while reading from the source stream.protected final void readStreamHeader()
throws IOException,
StreamCorruptedException
readStreamHeader in class ObjectInputStreamIOException - if an error occurs while reading from the source stream.StreamCorruptedException - if the source stream does not contain readable serialized
objects.public int readUnsignedByte()
throws IOException
readUnsignedByte in interface DataInputreadUnsignedByte in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public int readUnsignedShort()
throws IOException
readUnsignedShort in interface DataInputreadUnsignedShort in class ObjectInputStreamEOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public String readUTF() throws IOException
modified UTF-8 from the
source stream.readUTF in interface DataInputreadUTF in class ObjectInputStreammodified UTF-8 read from
the source stream.EOFException - if the end of the input is reached before the read
request can be satisfied.IOException - if an error occurs while reading from the source stream.public void registerValidation(ObjectInputValidation object, int priority) throws NotActiveException, InvalidObjectException
readObject() method of this class returns its result to the caller. This
method can only be called from within the readObject() method of
a class that implements "special" deserialization rules. It can be called
multiple times. Validation callbacks are then done in order of decreasing
priority, defined by priority.registerValidation in class ObjectInputStreamobject - an object that can validate itself by receiving a callback.priority - the validator's priority.InvalidObjectException - if object is null.NotActiveException - if this stream is currently not reading objects. In that
case, calling this method is not allowed.ObjectInputValidation.validateObject()public int skipBytes(int length)
throws IOException
length bytes on the source stream. This method should not
be used to skip bytes at any arbitrary position, just when reading
primitive data types (int, char etc).skipBytes in interface DataInputskipBytes in class ObjectInputStreamlength - the number of bytes to skip.IOException - if an error occurs while skipping bytes on the source stream.NullPointerException - if the source stream is null.Copyright © 2016–2018 The Apache Software Foundation. All rights reserved.