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:
java.io.Closeable
,java.io.DataInput
,java.lang.AutoCloseable
,ByteInput
- Direct Known Subclasses:
AbstractObjectInput
public class SimpleDataInput extends ByteInputStream implements java.io.DataInput
A simple base implementation ofDataInput
which wraps aByteInput
. This implementation maintains an internal buffer.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buffer
The internal buffer.protected int
limit
The buffer limit.protected int
position
The 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 Static Methods Instance Methods Concrete 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
close()
private static java.io.EOFException
eofOnRead()
protected void
finish()
Finish reading from the current input.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[] b, 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[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
protected int
readIntDirect()
Read an int value.java.lang.String
readLine()
long
readLong()
protected long
readLongDirect()
short
readShort()
int
readUnsignedByte()
protected int
readUnsignedByteDirect()
Read an unsigned byte directly.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 n)
protected void
start(ByteInput byteInput)
Start reading from the given input.
-
-
-
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 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.- Specified by:
read
in interfaceByteInput
- Overrides:
read
in classByteInputStream
- Returns:
- the next byte, or -1 if the end of stream has been reached
- Throws:
java.io.IOException
- if an error occurs
-
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.- Specified by:
read
in interfaceByteInput
- Overrides:
read
in 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:
java.io.IOException
- if an error occurs
-
read
public int read(byte[] b, 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
- Overrides:
read
in 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:
java.io.IOException
- if an error occurs
-
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)
.- Specified by:
skip
in interfaceByteInput
- Overrides:
skip
in classByteInputStream
- Parameters:
n
- the number of bytes to attempt to skip- Returns:
- the number of bytes skipped
- 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.- Specified by:
available
in interfaceByteInput
- Overrides:
available
in classByteInputStream
- Returns:
- the number of bytes
- Throws:
java.io.IOException
- if an error occurs
-
eofOnRead
private static java.io.EOFException eofOnRead()
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
skipBytes
public int skipBytes(int n) throws java.io.IOException
- Specified by:
skipBytes
in interfacejava.io.DataInput
- 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
-
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
-
readUnsignedByteDirect
protected int readUnsignedByteDirect() throws java.io.IOException
Read an unsigned byte directly.- Returns:
- the unsigned byte
- Throws:
java.io.IOException
- if an error occurs
-
readChar
public char readChar() throws java.io.IOException
- Specified by:
readChar
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
-
readLongDirect
protected long readLongDirect() throws java.io.IOException
- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Specified by:
readFloat
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readIntDirect
protected int readIntDirect() throws java.io.IOException
Read an int value.- Returns:
- the value
- Throws:
java.io.IOException
- if an error occurs
-
readDouble
public double readDouble() throws java.io.IOException
- Specified by:
readDouble
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException
- 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
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classByteInputStream
- Throws:
java.io.IOException
-
start
protected void start(ByteInput byteInput) throws java.io.IOException
Start reading from the given input. The internal buffer is discarded.- Parameters:
byteInput
- the new input from which to read- Throws:
java.io.IOException
- not thrown by this implementation, but may be overridden to be thrown if a problem occurs
-
finish
protected void finish() throws java.io.IOException
Finish reading from the current input. The internal buffer is discarded, not flushed.- Throws:
java.io.IOException
- not thrown by this implementation, but may be overridden to be thrown if a problem occurs
-
-