Class ByteArrayBuffer
- java.lang.Object
-
- org.apache.sshd.common.util.buffer.Buffer
-
- org.apache.sshd.common.util.buffer.ByteArrayBuffer
-
- All Implemented Interfaces:
Readable
- Direct Known Subclasses:
SessionWorkBuffer
public class ByteArrayBuffer extends Buffer
Provides an implementation ofBuffer
using a backing byte array
-
-
Constructor Summary
Constructors Constructor Description ByteArrayBuffer()
Allocates 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
array()
int
available()
int
capacity()
Buffer
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)
Buffer
ensureCapacity(int capacity, java.util.function.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 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)
java.lang.String
getString(java.nio.charset.Charset charset)
Reads a string using a given charset.void
putBuffer(java.nio.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)
-
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 Detail
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE
Initial default allocated buffer size if none specified- See Also:
- Constant Field Values
-
data
private byte[] data
-
rpos
private int rpos
-
wpos
private int wpos
-
-
Constructor Detail
-
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(int, boolean)
-
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(byte[], boolean)
-
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(byte[], int, int, boolean)
-
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 Detail
-
rpos
public void rpos(int rpos)
-
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
public Buffer clear(boolean wipeData)
Description copied from class:Buffer
Reset read/write positions to zero
-
putBuffer
public int putBuffer(Readable buffer, boolean expand)
-
putBuffer
public void putBuffer(java.nio.ByteBuffer buffer)
-
putRawBytes
public void putRawBytes(byte[] d, int off, int len)
- Specified by:
putRawBytes
in classBuffer
-
getString
public java.lang.String getString(java.nio.charset.Charset charset)
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
public Buffer ensureCapacity(int capacity, java.util.function.IntUnaryOperator growthFactor)
- 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
public static ByteArrayBuffer getCompactClone(byte[] data)
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(byte[], int, int)
-
getCompactClone
public 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- 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
-
-