Package org.jboss.marshalling
Class SimpleDataInput
- java.lang.Object
-
- java.io.InputStream
-
- org.jboss.marshalling.SimpleByteInput
-
- org.jboss.marshalling.ByteInputStream
-
- org.jboss.marshalling.SimpleDataInput
-
- All Implemented Interfaces:
Closeable,DataInput,AutoCloseable,ByteInput
- Direct Known Subclasses:
AbstractObjectInput
public class SimpleDataInput extends ByteInputStream implements DataInput
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufferThe internal buffer.protected intlimitThe buffer limit.protected intpositionThe buffer position.-
Fields inherited from class org.jboss.marshalling.ByteInputStream
byteInput
-
-
Constructor Summary
Constructors Constructor Description SimpleDataInput(int bufferSize)Construct a new instance which wraps nothing.SimpleDataInput(int bufferSize, ByteInput byteInput)Construct a new instance.SimpleDataInput(ByteInput byteInput)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete 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.voidclose()protected voidfinish()Finish reading from the current input.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[] b, int off, int len)Read some bytes from the input stream into the given array.booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()protected intreadIntDirect()Read an int value.StringreadLine()longreadLong()protected longreadLongDirect()shortreadShort()intreadUnsignedByte()protected intreadUnsignedByteDirect()Read an unsigned byte directly.intreadUnsignedShort()StringreadUTF()longskip(long n)Skips over and discards up tonbytes of data from this input stream.intskipBytes(int n)protected voidstart(ByteInput byteInput)Start reading from the given input.-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
-
-
-
-
Constructor Detail
-
SimpleDataInput
public SimpleDataInput(int bufferSize)
Construct a new instance which wraps nothing.- Parameters:
bufferSize- the internal buffer size to use
-
SimpleDataInput
public SimpleDataInput(int bufferSize, ByteInput byteInput)Construct a new instance.- Parameters:
bufferSize- the internal buffer size to usebyteInput- the byte input to initially wrap
-
SimpleDataInput
public SimpleDataInput(ByteInput byteInput)
Construct a new instance. A default buffer size is used.- Parameters:
byteInput- the byte input to initially wrap
-
-
Method Detail
-
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- Overrides:
readin classByteInputStream- 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[] 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- Overrides:
readin classByteInputStream- 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
-
read
public int read(byte[] b, 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- Overrides:
readin classByteInputStream- Parameters:
b- 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
-
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- Overrides:
skipin classByteInputStream- Parameters:
n- the number of bytes to attempt to skip- Returns:
- the number of bytes skipped
- 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- Overrides:
availablein classByteInputStream- Returns:
- the number of bytes
- Throws:
IOException- if an error occurs
-
readFully
public void readFully(byte[] b) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException- Specified by:
skipBytesin interfaceDataInput- 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
-
readShort
public short readShort() throws IOException- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readUnsignedByteDirect
protected int readUnsignedByteDirect() throws IOExceptionRead an unsigned byte directly.- Returns:
- the unsigned byte
- Throws:
IOException- if an error occurs
-
readChar
public char readChar() throws IOException- Specified by:
readCharin 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
-
readLongDirect
protected long readLongDirect() throws IOException- Throws:
IOException
-
readFloat
public float readFloat() throws IOException- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readIntDirect
protected int readIntDirect() throws IOExceptionRead an int value.- Returns:
- the value
- Throws:
IOException- if an error occurs
-
readDouble
public double readDouble() throws IOException- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classByteInputStream- Throws:
IOException
-
start
protected void start(ByteInput byteInput) throws IOException
Start reading from the given input. The internal buffer is discarded.- Parameters:
byteInput- the new input from which to read- Throws:
IOException- not thrown by this implementation, but may be overridden to be thrown if a problem occurs
-
finish
protected void finish() throws IOExceptionFinish reading from the current input. The internal buffer is discarded, not flushed.- Throws:
IOException- not thrown by this implementation, but may be overridden to be thrown if a problem occurs
-
-