public class ByteSource extends Object implements Resetable
ByteSource is a wrapper around byte array. It maintains vital fields
such as position, limit and capacity to facilitate better reading process.
ByteSource is unidirectional (can be read only in one direction);
however it offers random access using index.
position is is the index of first byte which will be read. limit is the index of first byte which will not be read.
| Modifier and Type | Class and Description |
|---|---|
static class |
ByteSource.ByteRange
Range captures a byte range with a start index and an end index.
|
| Constructor and Description |
|---|
ByteSource(byte[] bytes) |
ByteSource(byte[] bytes,
int position,
int limit) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
bytes() |
int |
capacity() |
void |
get(byte[] src)
Copies remaining byte data of this
ByteSource into the src byte
array. |
void |
get(byte[] src,
int srcPos)
Copies remaining byte data of this
ByteSource into the src byte
starting from the srcPos. |
void |
get(byte[] src,
int srcPos,
int length)
Copies bytes data of this
ByteSource into the src byte starting
from the srcPos. |
byte |
get(int index)
Returns the byte at the index.
|
int |
getPosition() |
boolean |
hasNext()
Returns true if there is another byte which can be read from this
ByteSource |
int |
limit()
Returns limit of this byte source.
|
byte |
next()
Reads next byte from data source; after reading the byte, position moves
to next byte.
|
int |
position() |
void |
reload(byte[] bytes)
Reloads this
ByteSource with given bytes. |
void |
reload(byte[] bytes,
int position)
Reloads this
ByteSource with given bytes. |
void |
reload(byte[] bytes,
int position,
int limit)
Reloads this
ByteSource with given bytes |
int |
remaining()
Number of chars remainig in this
ByteSource. |
void |
reset(boolean full)
Flushes out data, repositions counters and markers held by this object
|
void |
setPosition(int position)
Sets position index to the given value
|
public ByteSource(byte[] bytes)
public ByteSource(byte[] bytes,
int position,
int limit)
public byte[] bytes()
public int position()
public int limit()
public int capacity()
public int getPosition()
public byte next()
public final boolean hasNext()
ByteSourcepublic byte get(int index)
index - index of the bytepublic void get(byte[] src)
ByteSource into the src byte
array. If the length of src array is smaller than the remaining content,
the method will throw ArrayIndexOutOfBoundsExceptionsrc - srcpublic void get(byte[] src,
int srcPos)
ByteSource into the src byte
starting from the srcPos. If the length of src array is smaller than the
remaining content, the method will throw
ArrayIndexOutOfBoundsExceptionsrc - srcsrcPos - srcPospublic void get(byte[] src,
int srcPos,
int length)
ByteSource into the src byte starting
from the srcPos. If the length of src array is smaller than the remaining
content, the method will throw ArrayIndexOutOfBoundsExceptionsrc - srcsrcPos - srcPoslength - lengthpublic void reset(boolean full)
Resetablepublic void reload(byte[] bytes)
ByteSource with given bytes. The position of the
byte source will be set to zero and limit will be set to the length of
the byte array.bytes - bytes array (data)public void reload(byte[] bytes,
int position)
ByteSource with given bytes. The position of the
byte source will be set to the position supplied and limit will be set to
the length of the byte array.bytes - bytes array (data)position - position from which reading will startpublic void reload(byte[] bytes,
int position,
int limit)
ByteSource with given bytesbytes - bytes array (data)position - position from which reading will startlimit - boundary index. The reading cursor will always be behind the
boundarypublic void setPosition(int position)
position - positionpublic int remaining()
ByteSource. The number is
position variables; although at any point underlying
array has all the elements.Copyright © 2019. All rights reserved.