Package org.jboss.marshalling
Class ObjectInputStreamUnmarshaller
- java.lang.Object
-
- org.jboss.marshalling.ObjectInputStreamUnmarshaller
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.io.ObjectInput
,java.lang.AutoCloseable
,ByteInput
,Unmarshaller
public class ObjectInputStreamUnmarshaller extends java.lang.Object implements Unmarshaller
An Unmarshaller which simply wraps an object stream. Useful for retrofitting and testing applications.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.ObjectInputStream
ois
-
Constructor Summary
Constructors Constructor Description ObjectInputStreamUnmarshaller(java.io.ObjectInputStream ois)
Construct a new instance which wraps the given stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
available()
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.void
clearClassCache()
Discard the class cache.void
clearInstanceCache()
Discard the instance cache.void
close()
void
finish()
Finish unmarshalling from a stream.int
read()
Reads the next byte of data from the input stream.int
read(byte[] b)
Read some bytes from the input stream into the given array.int
read(byte[] buf, int off, int len)
Read some bytes from the input stream into the given array.boolean
readBoolean()
byte
readByte()
char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] buf)
void
readFully(byte[] buf, int off, int len)
int
readInt()
java.lang.String
readLine()
Deprecated.long
readLong()
java.lang.Object
readObject()
<T> T
readObject(java.lang.Class<T> type)
Read and return an object, cast to a specific type.java.lang.Object
readObjectUnshared()
Read and return an unshared object.<T> T
readObjectUnshared(java.lang.Class<T> type)
Read and return an unshared object, cast to a specific type.short
readShort()
int
readUnsignedByte()
int
readUnsignedShort()
java.lang.String
readUTF()
long
skip(long n)
Skips over and discards up ton
bytes of data from this input stream.int
skipBytes(int len)
void
start(ByteInput newInput)
Begin unmarshalling from a stream.private static java.io.InvalidObjectException
wrongType(java.lang.ClassCastException e, java.lang.Class<?> expected, java.lang.Class<?> actual)
-
-
-
Method Detail
-
readObject
public java.lang.Object readObject() throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readObject
in interfacejava.io.ObjectInput
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
readObjectUnshared
public java.lang.Object readObjectUnshared() throws java.io.IOException, java.lang.ClassNotFoundException
Read and return an unshared object.- Specified by:
readObjectUnshared
in interfaceUnmarshaller
- Returns:
- an unshared object
- Throws:
java.io.IOException
- if an error occursjava.lang.ClassNotFoundException
- if the class of a serialized object cannot be found
-
read
public int read() throws java.io.IOException
Reads the next byte of data from the input stream. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
-
read
public int read(byte[] buf, int off, int len) throws java.io.IOException
Read some bytes from the input stream into the given array. Returns the number of bytes actually read (possibly zero), or -1 if the end of stream has been reached.- Specified by:
read
in interfaceByteInput
- Specified by:
read
in interfacejava.io.ObjectInput
- Parameters:
buf
- the destination arrayoff
- the offset into the array into which data should be readlen
- the number of bytes to attempt to fill in the destination array- Returns:
- the number of bytes read (possibly zero), or -1 if the end of stream has been reached
- Throws:
java.io.IOException
- if an error occurs
-
available
public int available() throws java.io.IOException
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfacejava.io.ObjectInput
- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException
- Specified by:
readBoolean
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException
- Specified by:
readByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException
- Specified by:
readChar
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException
- Specified by:
readShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException
- Specified by:
readInt
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
- Specified by:
readLong
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Specified by:
readFloat
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
- Specified by:
readDouble
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] buf) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] buf, int off, int len) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
skipBytes
public int skipBytes(int len) throws java.io.IOException
- Specified by:
skipBytes
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLine
@Deprecated public java.lang.String readLine() throws java.io.IOException
Deprecated.- Specified by:
readLine
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Specified by:
readUTF
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
Read some bytes from the input stream into the given array. Returns the number of bytes actually read (possibly zero), or -1 if the end of stream has been reached.
-
skip
public long skip(long n) throws java.io.IOException
Skips over and discards up ton
bytes of data from this input stream. If the end of stream is reached, this method returns0
in order to be consistent withInputStream.skip(long)
.
-
start
public void start(ByteInput newInput) throws java.io.IOException
Begin unmarshalling from a stream.- Specified by:
start
in interfaceUnmarshaller
- Parameters:
newInput
- the new stream- Throws:
java.io.IOException
- if an error occurs during setup, such as an invalid header
-
clearInstanceCache
public void clearInstanceCache() throws java.io.IOException
Discard the instance cache.- Specified by:
clearInstanceCache
in interfaceUnmarshaller
- Throws:
java.io.IOException
- if an error occurs
-
clearClassCache
public void clearClassCache() throws java.io.IOException
Discard the class cache. Implicitly also discards the instance cache.- Specified by:
clearClassCache
in interfaceUnmarshaller
- Throws:
java.io.IOException
- if an error occurs
-
finish
public void finish() throws java.io.IOException
Finish unmarshalling from a stream. Any transient class or instance cache is discarded.- Specified by:
finish
in interfaceUnmarshaller
- Throws:
java.io.IOException
- if an error occurs
-
readObject
public <T> T readObject(java.lang.Class<T> type) throws java.lang.ClassNotFoundException, java.io.IOException
Read and return an object, cast to a specific type.- Specified by:
readObject
in interfaceUnmarshaller
- Type Parameters:
T
- the object type- Parameters:
type
- the object class- Returns:
- the object read from the stream
- Throws:
java.lang.ClassNotFoundException
- if the class of a serialized object cannot be foundjava.io.InvalidObjectException
- if the object is not of the expected typejava.io.IOException
- if an error occurs
-
readObjectUnshared
public <T> T readObjectUnshared(java.lang.Class<T> type) throws java.lang.ClassNotFoundException, java.io.IOException
Read and return an unshared object, cast to a specific type.- Specified by:
readObjectUnshared
in interfaceUnmarshaller
- Type Parameters:
T
- the object type- Parameters:
type
- the object class- Returns:
- an unshared object
- Throws:
java.lang.ClassNotFoundException
- if the class of a serialized object cannot be foundjava.io.InvalidObjectException
- if the object is not of the expected typejava.io.IOException
- if an error occurs
-
wrongType
private static java.io.InvalidObjectException wrongType(java.lang.ClassCastException e, java.lang.Class<?> expected, java.lang.Class<?> actual)
-
-