Package org.jboss.marshalling
Class ObjectInputStreamUnmarshaller
- java.lang.Object
-
- org.jboss.marshalling.ObjectInputStreamUnmarshaller
-
- All Implemented Interfaces:
Closeable,DataInput,ObjectInput,AutoCloseable,ByteInput,Unmarshaller
public class ObjectInputStreamUnmarshaller extends Object implements Unmarshaller
An Unmarshaller which simply wraps an object stream. Useful for retrofitting and testing applications.
-
-
Constructor Summary
Constructors Constructor Description ObjectInputStreamUnmarshaller(ObjectInputStream ois)Construct a new instance which wraps the given stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intavailable()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.voidclearClassCache()Discard the class cache.voidclearInstanceCache()Discard the instance cache.voidclose()voidfinish()Finish unmarshalling from a stream.intread()Reads the next byte of data from the input stream.intread(byte[] b)Read some bytes from the input stream into the given array.intread(byte[] buf, int off, int len)Read some bytes from the input stream into the given array.booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] buf)voidreadFully(byte[] buf, int off, int len)intreadInt()StringreadLine()Deprecated.longreadLong()ObjectreadObject()<T> TreadObject(Class<T> type)Read and return an object, cast to a specific type.ObjectreadObjectUnshared()Read and return an unshared object.<T> TreadObjectUnshared(Class<T> type)Read and return an unshared object, cast to a specific type.shortreadShort()intreadUnsignedByte()intreadUnsignedShort()StringreadUTF()longskip(long n)Skips over and discards up tonbytes of data from this input stream.intskipBytes(int len)voidstart(ByteInput newInput)Begin unmarshalling from a stream.
-
-
-
Constructor Detail
-
ObjectInputStreamUnmarshaller
public ObjectInputStreamUnmarshaller(ObjectInputStream ois)
Construct a new instance which wraps the given stream.- Parameters:
ois- the object stream to wrap
-
-
Method Detail
-
readObject
public Object readObject() throws IOException, ClassNotFoundException
- Specified by:
readObjectin interfaceObjectInput- Throws:
IOExceptionClassNotFoundException
-
readObjectUnshared
public Object readObjectUnshared() throws IOException, ClassNotFoundException
Read and return an unshared object.- Specified by:
readObjectUnsharedin interfaceUnmarshaller- Returns:
- an unshared object
- Throws:
IOException- if an error occursClassNotFoundException- if the class of a serialized object cannot be found
-
read
public int read() throws IOExceptionReads 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:
readin interfaceByteInput- Specified by:
readin interfaceObjectInput- Returns:
- the next byte, or -1 if the end of stream has been reached
- Throws:
IOException- if an error occurs
-
read
public int read(byte[] buf, int off, int len) throws IOExceptionRead 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:
readin interfaceByteInput- Specified by:
readin 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
public int available() throws IOExceptionReturns 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:
availablein interfaceByteInput- Specified by:
availablein interfaceObjectInput- Returns:
- the number of bytes
- Throws:
IOException- if an error occurs
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceObjectInput- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
public byte readByte() throws IOException- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readChar
public char readChar() throws IOException- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readShort
public short readShort() throws IOException- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readInt
public int readInt() throws IOException- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLong
public long readLong() throws IOException- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readFloat
public float readFloat() throws IOException- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readDouble
public double readDouble() throws IOException- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readFully
public void readFully(byte[] buf) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
public void readFully(byte[] buf, int off, int len) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
skipBytes
public int skipBytes(int len) throws IOException- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
readLine
@Deprecated public String readLine() throws IOException
Deprecated.- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
read
public int read(byte[] b) throws IOExceptionRead 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:
readin interfaceByteInput- Specified by:
readin 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
public long skip(long n) throws IOExceptionSkips over and discards up tonbytes of data from this input stream. If the end of stream is reached, this method returns0in order to be consistent withInputStream.skip(long).- Specified by:
skipin interfaceByteInput- Specified by:
skipin interfaceObjectInput- Parameters:
n- the number of bytes to attempt to skip- Returns:
- the number of bytes skipped
- Throws:
IOException- if an error occurs
-
start
public void start(ByteInput newInput) throws IOException
Begin unmarshalling from a stream.- Specified by:
startin interfaceUnmarshaller- Parameters:
newInput- the new stream- Throws:
IOException- if an error occurs during setup, such as an invalid header
-
clearInstanceCache
public void clearInstanceCache() throws IOExceptionDiscard the instance cache.- Specified by:
clearInstanceCachein interfaceUnmarshaller- Throws:
IOException- if an error occurs
-
clearClassCache
public void clearClassCache() throws IOExceptionDiscard the class cache. Implicitly also discards the instance cache.- Specified by:
clearClassCachein interfaceUnmarshaller- Throws:
IOException- if an error occurs
-
finish
public void finish() throws IOExceptionFinish unmarshalling from a stream. Any transient class or instance cache is discarded.- Specified by:
finishin interfaceUnmarshaller- Throws:
IOException- if an error occurs
-
readObject
public <T> T readObject(Class<T> type) throws ClassNotFoundException, IOException
Read and return an object, cast to a specific type.- Specified by:
readObjectin 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 foundInvalidObjectException- if the object is not of the expected typeIOException- if an error occurs
-
readObjectUnshared
public <T> T readObjectUnshared(Class<T> type) throws ClassNotFoundException, IOException
Read and return an unshared object, cast to a specific type.- Specified by:
readObjectUnsharedin interfaceUnmarshaller- Type Parameters:
T- the object type- Parameters:
type- the object class- Returns:
- an unshared object
- Throws:
ClassNotFoundException- if the class of a serialized object cannot be foundInvalidObjectException- if the object is not of the expected typeIOException- if an error occurs
-
-