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
Provides an implementation of
Buffer using a backing byte array-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]static final intInitial default allocated buffer size if none specifiedprivate intprivate int -
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()intintcapacity()clear(boolean wipeData) Reset read/write positions to zerovoidcompact()"Shift" the internal data so that reading starts from position zero.protected voidcopyRawBytes(int offset, byte[] buf, int pos, int len) ensureCapacity(int capacity, IntUnaryOperator growthFactor) bytegetByte()byte[]static ByteArrayBuffergetCompactClone(byte[] data) Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original datastatic ByteArrayBuffergetCompactClone(byte[] data, int offset, int len) Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original datavoidgetRawBytes(byte[] buf, int off, int len) Reads a string using a given charset.voidputBuffer(ByteBuffer buffer) intvoidputByte(byte b) voidputRawBytes(byte[] d, int off, int len) byterawByte(int pos) longrawUInt(int pos) intrpos()voidrpos(int rpos) protected intsize()intwpos()voidwpos(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, getUShort, 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:
-
data
private byte[] data -
rpos
private int rpos -
wpos
private int wpos
-
-
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:
getBytesConsumedin classBuffer- Returns:
- The bytes consumed so far
-
rawByte
public byte rawByte(int pos) - Overrides:
rawBytein 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:
rawUIntin 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:BufferReset 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:
putRawBytesin classBuffer
-
getString
Description copied from class:BufferReads 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:
copyRawBytesin classBuffer
-
ensureCapacity
- Specified by:
ensureCapacityin classBuffer- Parameters:
capacity- The required capacitygrowthFactor- AnIntUnaryOperatorthat 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
ByteArrayBuffercontaining 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
ByteArrayBuffercontaining a copy of the original data starting at zero read position
-