public class ByteArrayBuffer extends Buffer
Buffer using a backing byte array| Modifier 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() |
byte[] |
getBytesConsumed() |
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) |
byte |
rawByte(int pos) |
long |
rawUInt(int pos) |
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, getNameList, getNameList, getNameList, getNameList, getPublicKey, getPublicKey, getRawBytes, getRawPublicKey, getRawPublicKey, getShort, getString, getStringList, getStringList, getStringList, getStringList, getUByte, getUInt, isValidMessageStructure, isValidMessageStructure, putAndWipeBytes, putAndWipeBytes, putAndWipeChars, putAndWipeChars, putAndWipeChars, putAndWipeChars, putBoolean, putBuffer, putBufferedData, putBytes, putBytes, putChars, putChars, putChars, putChars, putInt, putKeyPair, putLong, putMPInt, putMPInt, putNameList, putNameList, putNameList, putNameList, putOptionalBufferedData, putPublicKey, putRawBytes, putRawPublicKey, putRawPublicKeyBytes, putShort, putString, putString, putStringList, putStringList, toHex, toStringpublic 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 byte[] getBytesConsumed()
getBytesConsumed in class Bufferpublic byte rawByte(int pos)
rawByte in class Bufferpos - A position in the raw underlying data bytesread position.
Note: no validation is made whether the position lies within array boundariespublic long rawUInt(int pos)
rawUInt in class Bufferpos - A position in the raw underlying data bytesread position. Note: no validation is made whether the position and the required extra 4
bytes lie within array boundariespublic void compact()
Bufferpublic void clear(boolean wipeData)
Bufferpublic int putBuffer(Readable buffer, boolean expand)
public void putBuffer(ByteBuffer buffer)
public void putRawBytes(byte[] d,
int off,
int len)
putRawBytes in class Bufferpublic String getString(Charset charset)
Bufferpublic void getRawBytes(byte[] buf,
int off,
int len)
protected void copyRawBytes(int offset,
byte[] buf,
int pos,
int len)
copyRawBytes in class Bufferpublic void ensureCapacity(int capacity,
IntUnaryOperator growthFactor)
ensureCapacity in class Buffercapacity - 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 © 2018–2020 The Apache Software Foundation. All rights reserved.