Package org.fusesource.hawtbuf
Class DataByteArrayInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.fusesource.hawtbuf.DataByteArrayInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.DataInput
,java.lang.AutoCloseable
public final class DataByteArrayInputStream extends java.io.InputStream implements java.io.DataInput
Optimized ByteArrayInputStream that can be used more than once
-
-
Constructor Summary
Constructors Constructor Description DataByteArrayInputStream()
CreatesWireByteArrayInputStream
with a minmalist byte arrayDataByteArrayInputStream(byte[] buf)
Creates aStoreByteArrayInputStream
.DataByteArrayInputStream(Buffer buffer)
Creates aStoreByteArrayInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
int
getLength()
int
getPos()
byte[]
getRawData()
int
read()
Reads the next byte of data from this input stream.int
read(byte[] b, int off, int len)
Reads up tolen
bytes of data into an array of bytes from this input stream.boolean
readBoolean()
Buffer
readBuffer(int len)
byte
readByte()
char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
java.lang.String
readLine()
long
readLong()
short
readShort()
int
readUnsignedByte()
int
readUnsignedShort()
java.lang.String
readUTF()
int
readVarInt()
long
readVarLong()
int
readVarSignedInt()
long
readVarSignedLong()
void
restart()
void
restart(byte[] newBuff)
reset theStoreByteArrayInputStream
to use an new byte arrayvoid
restart(int size)
re-start the input stream - reusing the current buffervoid
restart(Buffer buffer)
reset theStoreByteArrayInputStream
to use an new Buffervoid
setLength(int length)
void
setPos(int pos)
int
size()
int
skip(int n)
int
skipBytes(int n)
-
-
-
Field Detail
-
buf
private byte[] buf
-
pos
private int pos
-
offset
private int offset
-
length
private int length
-
helper
protected AbstractVarIntSupport helper
-
-
Constructor Detail
-
DataByteArrayInputStream
public DataByteArrayInputStream(byte[] buf)
Creates aStoreByteArrayInputStream
.- Parameters:
buf
- the input buffer.
-
DataByteArrayInputStream
public DataByteArrayInputStream(Buffer buffer)
Creates aStoreByteArrayInputStream
.- Parameters:
buffer
- the input buffer.
-
DataByteArrayInputStream
public DataByteArrayInputStream()
CreatesWireByteArrayInputStream
with a minmalist byte array
-
-
Method Detail
-
restart
public void restart(Buffer buffer)
reset theStoreByteArrayInputStream
to use an new Buffer- Parameters:
buffer
-
-
restart
public void restart(int size)
re-start the input stream - reusing the current buffer- Parameters:
size
-
-
size
public int size()
- Returns:
- the size
-
getRawData
public byte[] getRawData()
- Returns:
- the underlying data array
-
readBuffer
public Buffer readBuffer(int len)
-
restart
public void restart(byte[] newBuff)
reset theStoreByteArrayInputStream
to use an new byte array- Parameters:
newBuff
-
-
restart
public void restart()
-
read
public int read()
Reads the next byte of data from this input stream. The value byte is returned as anint
in the range0
to255
. If no byte is available because the end of the stream has been reached, the value-1
is returned.This
read
method cannot block.- Specified by:
read
in classjava.io.InputStream
- Returns:
- the next byte of data, or
-1
if the end of the stream has been reached.
-
read
public int read(byte[] b, int off, int len)
Reads up tolen
bytes of data into an array of bytes from this input stream.- Overrides:
read
in classjava.io.InputStream
- Parameters:
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached.
-
available
public int available()
- Overrides:
available
in classjava.io.InputStream
- Returns:
- the number of bytes that can be read from the input stream without blocking.
-
readFully
public void readFully(byte[] b)
- Specified by:
readFully
in interfacejava.io.DataInput
-
readFully
public void readFully(byte[] b, int off, int len)
- Specified by:
readFully
in interfacejava.io.DataInput
-
skip
public int skip(int n)
-
skipBytes
public int skipBytes(int n)
- Specified by:
skipBytes
in interfacejava.io.DataInput
-
readBoolean
public boolean readBoolean()
- Specified by:
readBoolean
in interfacejava.io.DataInput
-
readByte
public byte readByte()
- Specified by:
readByte
in interfacejava.io.DataInput
-
readUnsignedByte
public int readUnsignedByte()
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
-
readShort
public short readShort()
- Specified by:
readShort
in interfacejava.io.DataInput
-
readUnsignedShort
public int readUnsignedShort()
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
-
readChar
public char readChar()
- Specified by:
readChar
in interfacejava.io.DataInput
-
readInt
public int readInt()
- Specified by:
readInt
in interfacejava.io.DataInput
-
readLong
public long readLong()
- Specified by:
readLong
in interfacejava.io.DataInput
-
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
-
readLine
public java.lang.String readLine()
- Specified by:
readLine
in interfacejava.io.DataInput
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Specified by:
readUTF
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
getPos
public int getPos()
-
setPos
public void setPos(int pos)
-
getLength
public int getLength()
-
setLength
public void setLength(int length)
-
readVarInt
public int readVarInt() throws java.io.IOException
- Throws:
java.io.IOException
-
readVarLong
public long readVarLong() throws java.io.IOException
- Throws:
java.io.IOException
-
readVarSignedInt
public int readVarSignedInt() throws java.io.IOException
- Throws:
java.io.IOException
-
readVarSignedLong
public long readVarSignedLong() throws java.io.IOException
- Throws:
java.io.IOException
-
-