Top Description Fields Constructors Methods
org.apache.sshd.common.util.buffer

public Class ByteArrayBuffer

extends Buffer
Class Inheritance
Imports
java.nio.ByteBuffer, java.nio.charset.Charset, java.util.Arrays, .Objects, java.util.function.IntUnaryOperator, org.apache.sshd.common.util.GenericUtils, .NumberUtils, .Readable, .ValidateUtils

Provides an implementation of Buffer using a backing byte array
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private byte[]
public static final int
DEFAULT_SIZE

Initial default allocated buffer size if none specified

private int
private int
Inherited from org.apache.sshd.common.util.buffer.Buffer:
workBuf

Constructor Summary

AccessConstructor and Description
public
ByteArrayBuffer()

Allocates a buffer for writing purposes with 256 bytes

public
ByteArrayBuffer(int
Initial buffer size - Note: it is rounded to the closest power of 2 that is greater or equal to it.
size
)

Allocates a buffer for writing purposes

public
ByteArrayBuffer(int
Initial buffer size
size
,
boolean
Whether to round it to closest power of 2 that is greater or equal to the specified size
roundOff
)

Allocates a buffer for writing purposes

public
ByteArrayBuffer(byte[]
Data bytes to read from
data
)

Wraps data bytes for reading

public
ByteArrayBuffer(byte[]
Data bytes to use
data
,
boolean
Whether the data bytes are for reading or writing
read
)

public
ByteArrayBuffer(byte[]
Data bytes to read from
data
,
int
Offset to read from
off
,
int
Available bytes from given offset
len
)

Wraps data bytes for reading

public
ByteArrayBuffer(byte[]
Data bytes to use
data
,
int
Offset to read/write (according to read parameter)
off
,
int
Available bytes from given offset
len
,
boolean
Whether the data bytes are for reading or writing
read
)

Method Summary

Modifier and TypeMethod and Description
public byte[]
public int
public int
public Buffer
clear(boolean
Whether to zero any previously existing data
wipeData
)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.clear.

Reset read/write positions to zero

public void
compact()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.compact.

"Shift" the internal data so that reading starts from position zero.

protected void
copyRawBytes(int offset, byte[] buf, int pos, int len)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.copyRawBytes.

public Buffer
ensureCapacity(int
The required capacity
capacity
,
IntUnaryOperator
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 thrown
growthFactor
)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.ensureCapacity.

public byte
public byte[]
public byte[]
public static ByteArrayBuffer

Returns:

A ByteArrayBuffer containing a copy of the original data starting at zero read position
getCompactClone
(byte[]
The original data buffer
data
)

Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original data

public static ByteArrayBuffer

Returns:

A ByteArrayBuffer containing a copy of the original data starting at zero read position
getCompactClone
(byte[]
The original data buffer
data
,
int
The offset of the valid data in the buffer
offset
,
int
The size (in bytes) of of the valid data in the buffer
len
)

Creates a compact buffer (i.e., one that starts at offset zero) containing a copy of the original data

public int
public void
getRawBytes(byte[] buf, int off, int len)

Implements org.apache.sshd.common.util.Readable.getRawBytes.

public String
getString(Charset
The Charset to use for the string bytes
charset
)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.getString.

Reads a string using a given charset.

public long
public int
putBuffer(Readable buffer, boolean expand)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.putBuffer.

public void
public void
public void
putBytes(byte[] b, int off, int len)

Overrides org.apache.sshd.common.util.buffer.Buffer.putBytes.

public void
public void
putRawBytes(byte[] d, int off, int len)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.putRawBytes.

public void
putUInt(long
The 32-bit value
i
)

Overrides org.apache.sshd.common.util.buffer.Buffer.putUInt.

Writes 32 bits

public byte
rawByte(int
A position in the raw underlying data bytes
pos
)

Overrides org.apache.sshd.common.util.buffer.Buffer.rawByte.

public long
rawUInt(int
A position in the raw underlying data bytes
pos
)

Overrides org.apache.sshd.common.util.buffer.Buffer.rawUInt.

public int
public void
rpos(int
Set current reading position
rpos
)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.rpos.

protected int
public int
public void
wpos(int
Set current writing position - Note: if necessary, the underlying data buffer will be increased so as to allow writing from the new position
wpos
)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.wpos.

Inherited from org.apache.sshd.common.util.buffer.Buffer:
cleardumpHexdumpHexensureAvailableensureCapacityextractECgetAvailableStringsgetAvailableStringsgetBooleangetBytesgetCertificateOptionsgetCertificateOptionsgetCompactDatagetKeyPairgetLonggetMPIntgetMPIntAsBytesgetNameListgetNameListgetNameListgetNameListgetPublicKeygetPublicKeygetRawBytesgetRawPublicKeygetRawPublicKeygetShortgetStringgetStringListgetStringListgetStringListgetStringListgetUBytegetUShortisValidMessageStructureisValidMessageStructureputAndWipeBytesputAndWipeBytesputAndWipeCharsputAndWipeCharsputAndWipeCharsputAndWipeCharsputBooleanputBufferputBufferedDataputBytesputCertificateOptionsputCertificateOptionsputCharsputCharsputCharsputCharsputKeyPairputLongputMPIntputMPIntputNameListputNameListputNameListputNameListputOptionalBufferedDataputPublicKeyputRawBytesputRawPublicKeyputRawPublicKeyBytesputShortputStringputStringputStringListputStringListtoHextoString

Field Detail

databack to summary
private byte[] data
DEFAULT_SIZEback to summary
public static final int DEFAULT_SIZE

Initial default allocated buffer size if none specified

rposback to summary
private int rpos
wposback to summary
private int wpos

Constructor Detail

ByteArrayBufferback to summary
public ByteArrayBuffer()

Allocates a buffer for writing purposes with 256 bytes

ByteArrayBufferback to summary
public ByteArrayBuffer(int size)

Allocates a buffer for writing purposes

Parameters
size:int

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)
ByteArrayBufferback to summary
public ByteArrayBuffer(int size, boolean roundOff)

Allocates a buffer for writing purposes

Parameters
size:int

Initial buffer size

roundOff:boolean

Whether to round it to closest power of 2 that is greater or equal to the specified size

ByteArrayBufferback to summary
public ByteArrayBuffer(byte[] data)

Wraps data bytes for reading

Parameters
data:byte[]

Data bytes to read from

See Also
ByteArrayBuffer(byte[], boolean)
ByteArrayBufferback to summary
public ByteArrayBuffer(byte[] data, boolean read)
Parameters
data:byte[]

Data bytes to use

read:boolean

Whether the data bytes are for reading or writing

ByteArrayBufferback to summary
public ByteArrayBuffer(byte[] data, int off, int len)

Wraps data bytes for reading

Parameters
data:byte[]

Data bytes to read from

off:int

Offset to read from

len:int

Available bytes from given offset

See Also
ByteArrayBuffer(byte[], int, int, boolean)
ByteArrayBufferback to summary
public ByteArrayBuffer(byte[] data, int off, int len, boolean read)
Parameters
data:byte[]

Data bytes to use

off:int

Offset to read/write (according to read parameter)

len:int

Available bytes from given offset

read:boolean

Whether the data bytes are for reading or writing

Method Detail

arrayback to summary
public byte[] array()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.array.

Returns:byte[]

Doc from org.apache.sshd.common.util.buffer.Buffer.array.

The raw underlying data bytes

Annotations
@Override
availableback to summary
public int available()

Implements org.apache.sshd.common.util.Readable.available.

Annotations
@Override
capacityback to summary
public int capacity()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.capacity.

Returns:int

Doc from org.apache.sshd.common.util.buffer.Buffer.capacity.

Number of bytes that can still be written without re-sizing the internal buffer

Annotations
@Override
clearback to summary
public Buffer clear(boolean wipeData)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.clear.

Doc from org.apache.sshd.common.util.buffer.Buffer.clear.

Reset read/write positions to zero

Parameters
wipeData:boolean

Whether to zero any previously existing data

Returns:Buffer

Reference to this buffer

Annotations
@Override
compactback to summary
public void compact()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.compact.

Doc from org.apache.sshd.common.util.buffer.Buffer.compact.

"Shift" the internal data so that reading starts from position zero.

Annotations
@Override
copyRawBytesback to summary
protected void copyRawBytes(int offset, byte[] buf, int pos, int len)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.copyRawBytes.

Annotations
@Override
ensureCapacityback to summary
public Buffer ensureCapacity(int capacity, IntUnaryOperator growthFactor)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.ensureCapacity.

Parameters
capacity:int

Doc from org.apache.sshd.common.util.buffer.Buffer.ensureCapacity.

The required capacity

growthFactor:IntUnaryOperator

Doc from org.apache.sshd.common.util.buffer.Buffer.ensureCapacity.

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 thrown

Returns:Buffer

Doc from org.apache.sshd.common.util.buffer.Buffer.ensureCapacity.

This buffer instance

Annotations
@Override
getByteback to summary
public byte getByte()

Overrides org.apache.sshd.common.util.buffer.Buffer.getByte.

Annotations
@Override
getBytesConsumedback to summary
public byte[] getBytesConsumed()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.getBytesConsumed.

Returns:byte[]

Doc from org.apache.sshd.common.util.buffer.Buffer.getBytesConsumed.

The bytes consumed so far

Annotations
@Override
getBytesConsumedback to summary
public byte[] getBytesConsumed(int from)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.getBytesConsumed.

Returns:byte[]

Doc from org.apache.sshd.common.util.buffer.Buffer.getBytesConsumed.

The bytes consumed since the given position

Annotations
@Override
getCompactCloneback to summary
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:byte[]

The original data buffer

Returns:ByteArrayBuffer

A ByteArrayBuffer containing a copy of the original data starting at zero read position

See Also
getCompactClone(byte[], int, int)
getCompactCloneback to summary
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:byte[]

The original data buffer

offset:int

The offset of the valid data in the buffer

len:int

The size (in bytes) of of the valid data in the buffer

Returns:ByteArrayBuffer

A ByteArrayBuffer containing a copy of the original data starting at zero read position

getIntback to summary
public int getInt()

Overrides org.apache.sshd.common.util.buffer.Buffer.getInt.

Annotations
@Override
getRawBytesback to summary
public void getRawBytes(byte[] buf, int off, int len)

Implements org.apache.sshd.common.util.Readable.getRawBytes.

Annotations
@Override
getStringback to summary
public String getString(Charset charset)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.getString.

Doc from org.apache.sshd.common.util.buffer.Buffer.getString.

Reads a string using a given charset.

Parameters
charset:Charset

The Charset to use for the string bytes

Returns:String

The read string

Annotations
@Override
getUIntback to summary
public long getUInt()

Overrides org.apache.sshd.common.util.buffer.Buffer.getUInt.

Annotations
@Override
putBufferback to summary
public int putBuffer(Readable buffer, boolean expand)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.putBuffer.

Annotations
@Override
putBufferback to summary
public void putBuffer(ByteBuffer buffer)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.putBuffer.

Annotations
@Override
putByteback to summary
public void putByte(byte b)

Overrides org.apache.sshd.common.util.buffer.Buffer.putByte.

Annotations
@Override
putBytesback to summary
public void putBytes(byte[] b, int off, int len)

Overrides org.apache.sshd.common.util.buffer.Buffer.putBytes.

Annotations
@Override
putIntback to summary
public void putInt(long i)

Overrides org.apache.sshd.common.util.buffer.Buffer.putInt.

Annotations
@Override
putRawBytesback to summary
public void putRawBytes(byte[] d, int off, int len)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.putRawBytes.

Annotations
@Override
putUIntback to summary
public void putUInt(long i)

Overrides org.apache.sshd.common.util.buffer.Buffer.putUInt.

Doc from org.apache.sshd.common.util.buffer.Buffer.putUInt.

Writes 32 bits

Parameters
i:long

The 32-bit value

Annotations
@Override
rawByteback to summary
public byte rawByte(int pos)

Overrides org.apache.sshd.common.util.buffer.Buffer.rawByte.

Parameters
pos:int

Doc from org.apache.sshd.common.util.buffer.Buffer.rawByte.

A position in the raw underlying data bytes

Returns:byte

Doc from org.apache.sshd.common.util.buffer.Buffer.rawByte.

The byte at the specified position without changing the current read position

Note

no validation is made whether the position lies within array boundaries

Annotations
@Override
rawUIntback to summary
public long rawUInt(int pos)

Overrides org.apache.sshd.common.util.buffer.Buffer.rawUInt.

Parameters
pos:int

Doc from org.apache.sshd.common.util.buffer.Buffer.rawUInt.

A position in the raw underlying data bytes

Returns:long

Doc from org.apache.sshd.common.util.buffer.Buffer.rawUInt.

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

Annotations
@Override
rposback to summary
public int rpos()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.rpos.

Returns:int

Doc from org.apache.sshd.common.util.buffer.Buffer.rpos.

Current reading position

Annotations
@Override
rposback to summary
public void rpos(int rpos)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.rpos.

Parameters
rpos:int

Doc from org.apache.sshd.common.util.buffer.Buffer.rpos.

Set current reading position

Annotations
@Override
sizeback to summary
protected int size()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.size.

Returns:int

Doc from org.apache.sshd.common.util.buffer.Buffer.size.

Current size of underlying backing data bytes array

Annotations
@Override
wposback to summary
public int wpos()

Implements abstract org.apache.sshd.common.util.buffer.Buffer.wpos.

Returns:int

Doc from org.apache.sshd.common.util.buffer.Buffer.wpos.

Current writing position

Annotations
@Override
wposback to summary
public void wpos(int wpos)

Implements abstract org.apache.sshd.common.util.buffer.Buffer.wpos.

Parameters
wpos:int

Doc from org.apache.sshd.common.util.buffer.Buffer.wpos.

Set current writing position - Note: if necessary, the underlying data buffer will be increased so as to allow writing from the new position

Annotations
@Override