Package org.jgroups.util
Class ByteArrayDataInputStream
java.lang.Object
java.io.InputStream
org.jgroups.util.ByteArrayDataInputStream
- All Implemented Interfaces:
Closeable,DataInput,AutoCloseable
Implements
DataInput over a byte[] buffer. This class is not thread safe.- Since:
- 3.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final byte[]protected static final ByteBufferprotected final intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionByteArrayDataInputStream(byte[] buf) ByteArrayDataInputStream(byte[] buf, int offset, int length) ByteArrayDataInputStream(ByteBuffer buffer) -
Method Summary
Modifier and TypeMethodDescriptionadvance(int amount) Advances the current position without reading any bytes.byte[]buffer()intcapacity()protected intcheckBounds(int pos) intlimit()intposition()position(int pos) intread()Reads the next byte of data from buf.intread(byte[] b, int off, int len) booleanreadBuffer(int len) Non-copying reading of len bytes from the input stream into aByteBuffer.bytereadByte()charreadChar()doublefloatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()readLine()longreadLong()shortintintreadUTF()intskipBytes(int n) toString()Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
buf
protected final byte[] buf -
pos
protected int pos -
limit
protected final int limit -
EMPTY
-
-
Constructor Details
-
ByteArrayDataInputStream
public ByteArrayDataInputStream(byte[] buf) -
ByteArrayDataInputStream
public ByteArrayDataInputStream(byte[] buf, int offset, int length) -
ByteArrayDataInputStream
-
ByteArrayDataInputStream
-
-
Method Details
-
position
-
buffer
public byte[] buffer() -
getBuffer
-
byteBuffer
-
position
public int position() -
limit
public int limit() -
capacity
public int capacity() -
advance
Advances the current position without reading any bytes. This can be useful to skip bytes if necessary or if the byte[] is read externally from this InputStream.- Parameters:
amount- the amount to move the position forward- Throws:
IndexOutOfBoundsException- if the amount to move and the current position is larger than the limit
-
read
public int read()Reads the next byte of data from buf. The value byte is returned as anintin the range0to255. If no byte is available because the end of the buffer has been reached, the value-1is returned.- Specified by:
readin classInputStream- Returns:
- the next byte of data, or
-1if the end of the stream has been reached.
-
read
public int read(byte[] b, int off, int len) - Overrides:
readin classInputStream
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readBuffer
Non-copying reading of len bytes from the input stream into aByteBuffer.Reads len bytes from the input stream and wraps them in a
ByteBuffer. Note that the buffer is pinned to a subrange of the underlying 'buf' byte[] array: make sure that the contents of 'buf' don't change until you're done with 'buf', or else you'll end up with unpredictable behavior. -
skipBytes
public int skipBytes(int n) -
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
toString
-
checkBounds
protected int checkBounds(int pos)
-