Package org.jboss.marshalling
Class ObjectInputStreamUnmarshaller
java.lang.Object
org.jboss.marshalling.ObjectInputStreamUnmarshaller
- All Implemented Interfaces:
Closeable
,DataInput
,ObjectInput
,AutoCloseable
,ByteInput
,Unmarshaller
An Unmarshaller which simply wraps an object stream. Useful for retrofitting and testing applications.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance which wraps the given stream. -
Method Summary
Modifier and TypeMethodDescriptionint
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
Discard the class cache.void
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
byte
readByte()
char
readChar()
double
float
void
readFully
(byte[] buf) void
readFully
(byte[] buf, int off, int len) int
readInt()
readLine()
Deprecated.long
readLong()
<T> T
readObject
(Class<T> type) Read and return an object, cast to a specific type.Read and return an unshared object.<T> T
readObjectUnshared
(Class<T> type) Read and return an unshared object, cast to a specific type.short
int
int
readUTF()
long
skip
(long n) Skips over and discards up ton
bytes of data from this input stream.int
skipBytes
(int len) void
Begin unmarshalling from a stream.private static InvalidObjectException
wrongType
(ClassCastException e, Class<?> expected, Class<?> actual)
-
Field Details
-
ois
-
-
Constructor Details
-
ObjectInputStreamUnmarshaller
Construct a new instance which wraps the given stream.- Parameters:
ois
- the object stream to wrap
-
-
Method Details
-
readObject
- Specified by:
readObject
in interfaceObjectInput
- Throws:
IOException
ClassNotFoundException
-
read
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.- Specified by:
read
in interfaceByteInput
- Specified by:
read
in interfaceObjectInput
- Returns:
- the next byte, or -1 if the end of stream has been reached
- Throws:
IOException
- if an error occurs
-
read
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 interfaceObjectInput
- 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:
IOException
- if an error occurs
-
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.- Specified by:
available
in interfaceByteInput
- Specified by:
available
in interfaceObjectInput
- Returns:
- the number of bytes
- Throws:
IOException
- if an error occurs
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceObjectInput
- Throws:
IOException
-
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readChar
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
skipBytes
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
readLine
Deprecated.- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
read
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 interfaceObjectInput
- Parameters:
b
- the destination array- Returns:
- the number of bytes read (possibly zero), or -1 if the end of stream has been reached
- Throws:
IOException
- if an error occurs
-
skip
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)
.- Specified by:
skip
in interfaceByteInput
- Specified by:
skip
in interfaceObjectInput
- Parameters:
n
- the number of bytes to attempt to skip- Returns:
- the number of bytes skipped
- Throws:
IOException
- if an error occurs
-
start
Begin unmarshalling from a stream.- Specified by:
start
in interfaceUnmarshaller
- Parameters:
newInput
- the new stream- Throws:
IOException
- if an error occurs during setup, such as an invalid header
-
clearInstanceCache
Discard the instance cache.- Specified by:
clearInstanceCache
in interfaceUnmarshaller
- Throws:
IOException
- if an error occurs
-
clearClassCache
Discard the class cache. Implicitly also discards the instance cache.- Specified by:
clearClassCache
in interfaceUnmarshaller
- Throws:
IOException
- if an error occurs
-
finish
Finish unmarshalling from a stream. Any transient class or instance cache is discarded.- Specified by:
finish
in interfaceUnmarshaller
- Throws:
IOException
- if an error occurs
-
readObject
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:
ClassNotFoundException
- if the class of a serialized object cannot be foundIOException
- if an error occurs
-
wrongType
private static InvalidObjectException wrongType(ClassCastException e, Class<?> expected, Class<?> actual)
-