Class ByteArrayBuffer
java.lang.Object
org.apache.sshd.common.util.buffer.Buffer
org.apache.sshd.common.util.buffer.ByteArrayBuffer
- All Implemented Interfaces:
Readable
Provides an implementation of
Buffer
using a backing byte array- Author:
- Apache MINA SSHD Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Initial default allocated buffer size if none specified -
Constructor Summary
ConstructorsConstructorDescriptionAllocates a buffer for writing purposes with 256 bytesByteArrayBuffer
(byte[] data) Wraps data bytes for readingByteArrayBuffer
(byte[] data, boolean read) ByteArrayBuffer
(byte[] data, int off, int len) Wraps data bytes for readingByteArrayBuffer
(byte[] data, int off, int len, boolean read) ByteArrayBuffer
(int size) Allocates a buffer for writing purposesByteArrayBuffer
(int size, boolean roundOff) Allocates a buffer for writing purposes -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
int
int
capacity()
clear
(boolean wipeData) Reset read/write positions to zerovoid
compact()
"Shift" the internal data so that reading starts from position zero.protected void
copyRawBytes
(int offset, byte[] buf, int pos, int len) ensureCapacity
(int capacity, IntUnaryOperator growthFactor) byte
getByte()
byte[]
static ByteArrayBuffer
getCompactClone
(byte[] data) Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original datastatic 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 datavoid
getRawBytes
(byte[] buf, int off, int len) Reads a string using a given charset.void
putBuffer
(ByteBuffer buffer) int
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) Methods inherited from class org.apache.sshd.common.util.buffer.Buffer
clear, dumpHex, dumpHex, ensureAvailable, ensureCapacity, extractEC, getAvailableStrings, getAvailableStrings, getBoolean, getBytes, getCertificateOptions, getCertificateOptions, 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, putCertificateOptions, putCertificateOptions, putChars, putChars, putChars, putChars, putInt, putKeyPair, putLong, putMPInt, putMPInt, putNameList, putNameList, putNameList, putNameList, putOptionalBufferedData, putPublicKey, putRawBytes, putRawPublicKey, putRawPublicKeyBytes, putShort, putString, putString, putStringList, putStringList, putUInt, toHex, toString
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEInitial default allocated buffer size if none specified- See Also:
-
-
Constructor Details
-
ByteArrayBuffer
public ByteArrayBuffer()Allocates a buffer for writing purposes with 256 bytes -
ByteArrayBuffer
public ByteArrayBuffer(int size) Allocates a buffer for writing purposes- Parameters:
size
- Initial buffer size - Note: it is rounded to the closest power of 2 that is greater or equal to it.- See Also:
-
ByteArrayBuffer
public ByteArrayBuffer(int size, boolean roundOff) Allocates a buffer for writing purposes- Parameters:
size
- Initial buffer sizeroundOff
- Whether to round it to closest power of 2 that is greater or equal to the specified size
-
ByteArrayBuffer
public ByteArrayBuffer(byte[] data) Wraps data bytes for reading- Parameters:
data
- Data bytes to read from- See Also:
-
ByteArrayBuffer
public ByteArrayBuffer(byte[] data, boolean read) - Parameters:
data
- Data bytes to useread
- Whether the data bytes are for reading or writing
-
ByteArrayBuffer
public ByteArrayBuffer(byte[] data, int off, int len) Wraps data bytes for reading- Parameters:
data
- Data bytes to read fromoff
- Offset to read fromlen
- Available bytes from given offset- See Also:
-
ByteArrayBuffer
public ByteArrayBuffer(byte[] data, int off, int len, boolean read) - Parameters:
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 writing
-
-
Method Details
-
rpos
public int rpos() -
rpos
public void rpos(int rpos) -
wpos
public int wpos() -
wpos
public void wpos(int wpos) -
available
public int available() -
capacity
public int capacity() -
array
public byte[] array() -
getBytesConsumed
public byte[] getBytesConsumed()- Specified by:
getBytesConsumed
in classBuffer
- Returns:
- The bytes consumed so far
-
rawByte
public byte rawByte(int pos) - Overrides:
rawByte
in classBuffer
- Parameters:
pos
- A position in the raw underlying data bytes- Returns:
- The byte at the specified position without changing the current
read position
. Note: no validation is made whether the position lies within array boundaries
-
rawUInt
public long rawUInt(int pos) - Overrides:
rawUInt
in classBuffer
- Parameters:
pos
- A position in the raw underlying data bytes- Returns:
- The unsigned 32 bit integer at the specified position without changing the current
read position
. Note: no validation is made whether the position and the required extra 4 bytes lie within array boundaries
-
compact
public void compact()Description copied from class:Buffer
"Shift" the internal data so that reading starts from position zero. -
clear
Description copied from class:Buffer
Reset read/write positions to zero -
getByte
public byte getByte() -
putByte
public void putByte(byte b) -
putBuffer
-
putBuffer
-
putRawBytes
public void putRawBytes(byte[] d, int off, int len) - Specified by:
putRawBytes
in classBuffer
-
getString
Description copied from class:Buffer
Reads a string using a given charset. -
getRawBytes
public void getRawBytes(byte[] buf, int off, int len) -
copyRawBytes
protected void copyRawBytes(int offset, byte[] buf, int pos, int len) - Specified by:
copyRawBytes
in classBuffer
-
ensureCapacity
- Specified by:
ensureCapacity
in classBuffer
- Parameters:
capacity
- The required capacitygrowthFactor
- AnIntUnaryOperator
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 thrown- Returns:
- This buffer instance
-
size
protected int size() -
getCompactClone
Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original data- Parameters:
data
- The original data buffer- Returns:
- A
ByteArrayBuffer
containing a copy of the original data starting at zero read position - See Also:
-
getCompactClone
Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original data- Parameters:
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 buffer- Returns:
- A
ByteArrayBuffer
containing a copy of the original data starting at zero read position
-