public class ByteArrayBuffer extends Buffer
Buffer
using a backing byte arrayModifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE
Initial default allocated buffer size if none specified
|
Constructor and Description |
---|
ByteArrayBuffer()
Allocates a buffer for writing purposes with 256 bytes
|
ByteArrayBuffer(byte[] data)
Wraps data bytes for reading
|
ByteArrayBuffer(byte[] data,
boolean read) |
ByteArrayBuffer(byte[] data,
int off,
int len)
Wraps data bytes for reading
|
ByteArrayBuffer(byte[] data,
int off,
int len,
boolean read) |
ByteArrayBuffer(int size)
Allocates a buffer for writing purposes
|
ByteArrayBuffer(int size,
boolean roundOff)
Allocates a buffer for writing purposes
|
Modifier and Type | Method and Description |
---|---|
byte[] |
array() |
int |
available() |
int |
capacity() |
void |
clear(boolean wipeData)
Reset read/write positions to zero
|
void |
compact()
"Shift" the internal data so that reading starts from
position zero.
|
protected void |
copyRawBytes(int offset,
byte[] buf,
int pos,
int len) |
void |
ensureCapacity(int capacity,
IntUnaryOperator growthFactor) |
byte |
getByte() |
static ByteArrayBuffer |
getCompactClone(byte[] data)
Creates a compact buffer (i.e., one that starts at offset zero) containing a copy
of the original data
|
static ByteArrayBuffer |
getCompactClone(byte[] data,
int offset,
int len)
Creates a compact buffer (i.e., one that starts at offset zero) containing a copy
of the original data
|
void |
getRawBytes(byte[] buf,
int off,
int len) |
String |
getString(Charset charset)
Reads a string using a given charset.
|
void |
putBuffer(ByteBuffer buffer) |
int |
putBuffer(Readable buffer,
boolean expand) |
void |
putByte(byte b) |
void |
putRawBytes(byte[] d,
int off,
int len) |
int |
rpos() |
void |
rpos(int rpos) |
protected int |
size() |
int |
wpos() |
void |
wpos(int wpos) |
clear, dumpHex, dumpHex, ensureAvailable, ensureCapacity, extractEC, getAvailableStrings, getAvailableStrings, getBoolean, getBytes, getCompactData, getInt, getKeyPair, getLong, getMPInt, getMPIntAsBytes, getPublicKey, getPublicKey, getRawBytes, getRawPublicKey, getRawPublicKey, getShort, getString, getStringList, getStringList, getStringList, getStringList, getUByte, getUInt, isValidMessageStructure, isValidMessageStructure, putAndWipeBytes, putAndWipeBytes, putAndWipeChars, putAndWipeChars, putAndWipeChars, putAndWipeChars, putBoolean, putBuffer, putBytes, putBytes, putChars, putChars, putChars, putChars, putInt, putKeyPair, putLong, putMPInt, putMPInt, putPublicKey, putRawBytes, putRawPublicKey, putShort, putString, putString, putStringList, putStringList, toHex, toString
public static final int DEFAULT_SIZE
public ByteArrayBuffer()
public ByteArrayBuffer(int size)
size
- Initial buffer size - Note: it is rounded to the
closest power of 2 that is greater or equal to it.ByteArrayBuffer(int, boolean)
public ByteArrayBuffer(int size, boolean roundOff)
size
- Initial buffer sizeroundOff
- Whether to round it to closest power of 2 that is greater or
equal to the specified sizepublic ByteArrayBuffer(byte[] data)
data
- Data bytes to read fromByteArrayBuffer(byte[], boolean)
public ByteArrayBuffer(byte[] data, boolean read)
data
- Data bytes to useread
- Whether the data bytes are for reading or writingpublic ByteArrayBuffer(byte[] data, int off, int len)
data
- Data bytes to read fromoff
- Offset to read fromlen
- Available bytes from given offsetByteArrayBuffer(byte[], int, int, boolean)
public ByteArrayBuffer(byte[] data, int off, int len, boolean read)
data
- Data bytes to useoff
- Offset to read/write (according to read parameter)len
- Available bytes from given offsetread
- Whether the data bytes are for reading or writingpublic void rpos(int rpos)
public void wpos(int wpos)
public int available()
public int capacity()
public byte[] array()
public void compact()
Buffer
public void clear(boolean wipeData)
Buffer
public int putBuffer(Readable buffer, boolean expand)
public void putBuffer(ByteBuffer buffer)
public void putRawBytes(byte[] d, int off, int len)
putRawBytes
in class Buffer
public String getString(Charset charset)
Buffer
public void getRawBytes(byte[] buf, int off, int len)
protected void copyRawBytes(int offset, byte[] buf, int pos, int len)
copyRawBytes
in class Buffer
public void ensureCapacity(int capacity, IntUnaryOperator growthFactor)
ensureCapacity
in class Buffer
capacity
- The required capacitygrowthFactor
- An IntUnaryOperator
that is invoked if the current
capacity is insufficient. The argument is the minimum required new data length,
the function result should be the effective new data length to be allocated - if
less than minimum then an exception is thrownprotected int size()
public static ByteArrayBuffer getCompactClone(byte[] data)
data
- The original data bufferByteArrayBuffer
containing a copy of the original data
starting at zero read positiongetCompactClone(byte[], int, int)
public static ByteArrayBuffer getCompactClone(byte[] data, int offset, int len)
data
- The original data bufferoffset
- The offset of the valid data in the bufferlen
- The size (in bytes) of of the valid data in the bufferByteArrayBuffer
containing a copy of the original data
starting at zero read positionCopyright © 2008–2022 The Apache Software Foundation. All rights reserved.