public class

Buffer

extends Object
java.lang.Object
   ↳ net.schmizz.sshj.common.Buffer<T extends net.schmizz.sshj.common.Buffer<T>>
Known Direct Subclasses
Known Indirect Subclasses

Summary

Nested Classes
class Buffer.BufferException  
class Buffer.PlainBuffer  
Constants
int DEFAULT_SIZE The default size for a Buffer (256 bytes)
int MAX_SIZE The maximum valid size of buffer (i.e.
Fields
protected byte[] data
protected int rpos
protected int wpos
Public Constructors
Buffer()
Buffer(Buffer<?> from)
Buffer(byte[] data)
Buffer(int size)
Public Methods
byte[] array()
int available()
void clear()
Resets this buffer.
void compact()
Compact this SSHPacket
void ensureCapacity(int capacity)
byte[] getCompactData()
String printHex()
Gives a readable snapshot of the buffer in hex.
T putBoolean(boolean b)
Puts an SSH boolean value
T putBuffer(Buffer<? extends Buffer<?>> buffer)
Copies the contents of provided buffer into this buffer
T putByte(byte b)
Writes a single byte into this buffer
T putBytes(byte[] b, int off, int len)
Writes Java byte-array as an SSH byte-array
T putBytes(byte[] b)
Writes Java byte-array as an SSH byte-array
T putMPInt(BigInteger bi)
T putPublicKey(PublicKey key)
T putRawBytes(byte[] d)
T putRawBytes(byte[] d, int off, int len)
T putSensitiveString(char[] str)
Writes a char-array as an SSH string and then blanks it out.
T putSignature(String sigFormat, byte[] sigData)
T putString(byte[] str)
T putString(String string)
T putString(byte[] str, int offset, int len)
T putUInt32(long uint32)
Writes a uint32 integer
T putUInt64(long uint64)
boolean readBoolean()
Read an SSH boolean byte
byte readByte()
Read a byte from the buffer
byte[] readBytes()
Read an SSH byte-array
BigInteger readMPInt()
Read an SSH multiple-precision integer
PublicKey readPublicKey()
void readRawBytes(byte[] buf, int off, int len)
void readRawBytes(byte[] buf)
String readString()
Reads an SSH string
byte[] readStringAsBytes()
Reads an SSH string
long readUInt32()
int readUInt32AsInt()
long readUInt64()
int rpos()
void rpos(int rpos)
String toString()
int wpos()
void wpos(int wpos)
Protected Methods
void ensureAvailable(int a)
static int getNextPowerOf2(int i)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEFAULT_SIZE

The default size for a Buffer (256 bytes)

Constant Value: 256 (0x00000100)

public static final int MAX_SIZE

The maximum valid size of buffer (i.e. biggest power of two that can be represented as an int - 2^30)

Constant Value: 1073741824 (0x40000000)

Fields

protected byte[] data

protected int rpos

protected int wpos

Public Constructors

public Buffer ()

See Also

public Buffer (Buffer<?> from)

Parameters
from

public Buffer (byte[] data)

Parameters
data

public Buffer (int size)

Parameters
size

Public Methods

public byte[] array ()

public int available ()

public void clear ()

Resets this buffer. The object becomes ready for reuse.

public void compact ()

Compact this SSHPacket

public void ensureCapacity (int capacity)

Parameters
capacity

public byte[] getCompactData ()

public String printHex ()

Gives a readable snapshot of the buffer in hex. This is useful for debugging.

Returns
  • snapshot of the buffer as a hex string with each octet delimited by a space

public T putBoolean (boolean b)

Puts an SSH boolean value

Parameters
b The value
Returns
  • this

public T putBuffer (Buffer<? extends Buffer<?>> buffer)

Copies the contents of provided buffer into this buffer

Parameters
buffer The Buffer to copy
Returns
  • this

public T putByte (byte b)

Writes a single byte into this buffer

Parameters
b
Returns
  • this

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

Writes Java byte-array as an SSH byte-array

Parameters
b Java byte-array
off Offset
len Length
Returns
  • this

public T putBytes (byte[] b)

Writes Java byte-array as an SSH byte-array

Parameters
b Java byte-array
Returns
  • this

public T putMPInt (BigInteger bi)

Parameters
bi

public T putPublicKey (PublicKey key)

Parameters
key

public T putRawBytes (byte[] d)

Parameters
d

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

Parameters
d
off
len

public T putSensitiveString (char[] str)

Writes a char-array as an SSH string and then blanks it out.

This is useful when a plaintext password needs to be sent. If str is null, an empty string is written.

Parameters
str (null-ok) the string as a character array
Returns
  • this

public T putSignature (String sigFormat, byte[] sigData)

Parameters
sigFormat
sigData

public T putString (byte[] str)

Parameters
str

public T putString (String string)

Parameters
string

public T putString (byte[] str, int offset, int len)

Parameters
str
offset
len

public T putUInt32 (long uint32)

Writes a uint32 integer

Parameters
uint32
Returns
  • this

public T putUInt64 (long uint64)

Parameters
uint64

public boolean readBoolean ()

Read an SSH boolean byte

Returns
  • the true or false value read

public byte readByte ()

Read a byte from the buffer

Returns
  • the byte read

public byte[] readBytes ()

Read an SSH byte-array

Returns
  • the byte-array read

public BigInteger readMPInt ()

Read an SSH multiple-precision integer

Returns
  • the MP integer as a BigInteger

public PublicKey readPublicKey ()

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

Parameters
buf
off
len

public void readRawBytes (byte[] buf)

Parameters
buf

public String readString ()

Reads an SSH string

Returns
  • the string as a Java String

public byte[] readStringAsBytes ()

Reads an SSH string

Returns
  • the string as a byte-array

public long readUInt32 ()

public int readUInt32AsInt ()

public long readUInt64 ()

public int rpos ()

public void rpos (int rpos)

Parameters
rpos

public String toString ()

public int wpos ()

public void wpos (int wpos)

Parameters
wpos

Protected Methods

protected void ensureAvailable (int a)

Parameters
a

protected static int getNextPowerOf2 (int i)

Parameters
i