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.
Modifier and Type | Class and Description |
---|---|
static class |
AtomicMarshalInputStream.Reference |
ObjectInputStream.GetField
baseWireHandle, 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 objectInputStreamCompatible)
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 MarshalInputStream |
create(InputStream in,
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader,
Collection context)
Static factory method to obtain an instance without checking for
SerializablePermission("enableSubclassImplementation")
|
static ObjectInputStream |
createObjectInputStream(InputStream in,
ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity,
ClassLoader verifierLoader,
Collection context)
The instance returned can de-serialize data written by
ObjectOutputStream , however it is not compatible
with MarshalOutputStream . |
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, useCodebaseAnnotations
readObject, resolveObject
mark, markSupported, read, reset, skip
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
read, skip
public 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 objectInputStreamCompatible) throws IOException
input
.input
- the non-null source InputStream to filter reads on.defaultLoader
- verifyCodebaseIntegrity
- verifierLoader
- context
- objectInputStreamCompatible
- if true is compatible with ObjectInputStream
otherwise, if false is 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 MarshalInputStream create(InputStream in, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException
in
- defaultLoader
- verifyCodebaseIntegrity
- verifierLoader
- context
- IOException
public static ObjectInputStream createObjectInputStream(InputStream in, ClassLoader defaultLoader, boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException
ObjectOutputStream
, however it is not compatible
with MarshalOutputStream
.in
- defaultLoader
- verifyCodebaseIntegrity
- verifierLoader
- context
- IOException
public int available() throws IOException
available
in interface ObjectInput
available
in class ObjectInputStream
IOException
- if any I/O problem occurs while computing the available
bytes.public void close() throws IOException
close
in interface Closeable
close
in interface ObjectInput
close
in interface AutoCloseable
close
in class ObjectInputStream
IOException
- if an error occurs while closing this stream.public void defaultReadObject() throws IOException, ClassNotFoundException, NotActiveException
defaultReadObject
in class ObjectInputStream
ClassNotFoundException
- 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 ObjectInputStream
enable
- 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 ObjectInput
read
in class ObjectInputStream
IOException
- 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 ObjectInput
read
in class ObjectInputStream
buffer
- 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
MarshalInputStream
null
) 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 MarshalInputStream
null
)IOException
- if an I/O exception occurs reading the
annotationClassNotFoundException
- if a
ClassNotFoundException
occurs reading the
annotationpublic boolean readBoolean() throws IOException
readBoolean
in interface DataInput
readBoolean
in class ObjectInputStream
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 byte readByte() throws IOException
readByte
in interface DataInput
readByte
in class ObjectInputStream
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 char readChar() throws IOException
readChar
in interface DataInput
readChar
in class ObjectInputStream
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 double readDouble() throws IOException
readDouble
in interface DataInput
readDouble
in class ObjectInputStream
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 ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException, NotActiveException
readFields
in class ObjectInputStream
ClassNotFoundException
- 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 DataInput
readFloat
in class ObjectInputStream
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) throws IOException
buffer
.
This method will block until buffer.length
bytes have been read.readFully
in interface DataInput
readFully
in class ObjectInputStream
buffer
- 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 DataInput
readFully
in class ObjectInputStream
buffer
- 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 DataInput
readInt
in class ObjectInputStream
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.@Deprecated public String readLine() throws IOException
BufferedReader
'\r'
, '\n'
, "\r\n"
or an EOF
.readLine
in interface DataInput
readLine
in class ObjectInputStream
IOException
- if an error occurs while reading from the source stream.public long readLong() throws IOException
readLong
in interface DataInput
readLong
in class ObjectInputStream
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.protected final ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException
readClassDescriptor
in class ObjectInputStream
ClassNotFoundException
- 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
IOException
ClassNotFoundException
protected final Object readObjectOverride() throws OptionalDataException, ClassNotFoundException, IOException
readObjectOverride
in class ObjectInputStream
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.OptionalDataException
- if primitive data types were found instead of an object.OptionalDataException
ObjectOutputStream.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 ObjectInputStream
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 <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 DataInput
readShort
in class ObjectInputStream
IOException
- if an error occurs while reading from the source stream.protected final void readStreamHeader() throws IOException, StreamCorruptedException
readStreamHeader
in class ObjectInputStream
IOException
- 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 DataInput
readUnsignedByte
in class ObjectInputStream
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 readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
readUnsignedShort
in class ObjectInputStream
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 String readUTF() throws IOException
modified UTF-8
from the
source stream.readUTF
in interface DataInput
readUTF
in class ObjectInputStream
modified 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 ObjectInputStream
object
- 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 DataInput
skipBytes
in class ObjectInputStream
length
- 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.