Package net.schmizz.sshj.common
Class Buffer<T extends Buffer<T>>
java.lang.Object
net.schmizz.sshj.common.Buffer<T>
- Direct Known Subclasses:
Buffer.PlainBuffer,SFTPPacket,SSHPacket
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]static final intThe default size for aBuffer(256 bytes)static final intThe maximum valid size of buffer (i.e.static final BigIntegerMaximum size of a uint64protected intprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]array()intvoidclear()Resets this buffer.voidcompact()Compact thisSSHPacketprotected voidensureAvailable(int a) voidensureCapacity(int capacity) byte[]protected static intgetNextPowerOf2(int i) printHex()Gives a readable snapshot of the buffer in hex.putBoolean(boolean b) Puts an SSH boolean valueCopies the contents of provided buffer into this bufferputByte(byte b) Writes a single byte into this bufferputBytes(byte[] b) Writes Java byte-array as an SSH byte-arrayputBytes(byte[] b, int off, int len) Writes Java byte-array as an SSH byte-arrayputMPInt(BigInteger bi) putPublicKey(PublicKey key) putRawBytes(byte[] d) putRawBytes(byte[] d, int off, int len) putSensitiveString(char[] str) Writes a char-array as an SSH string and then blanks it out.putSignature(String sigFormat, byte[] sigData) putString(byte[] str) putString(byte[] str, int offset, int len) putUInt32(long uint32) Writes a uint32 integerputUInt32FromInt(int uint32) Writes a uint32 integerputUInt64(long uint64) putUInt64(BigInteger uint64) private TputUInt64Unchecked(long uint64) booleanRead an SSH boolean bytebytereadByte()Read a byte from the bufferbyte[]Read an SSH byte-arrayRead an SSH multiple-precision integervoidreadRawBytes(byte[] buf) voidreadRawBytes(byte[] buf, int off, int len) Reads an SSH string usingUTF8readString(Charset cs) Reads an SSH stringbyte[]Reads an SSH stringlongintlongintrpos()voidrpos(int rpos) toString()intwpos()voidwpos(int wpos)
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEThe default size for aBuffer(256 bytes)- See Also:
-
MAX_SIZE
public static final int MAX_SIZEThe maximum valid size of buffer (i.e. biggest power of two that can be represented as an int - 2^30)- See Also:
-
MAX_UINT64_VALUE
Maximum size of a uint64 -
data
protected byte[] data -
rpos
protected int rpos -
wpos
protected int wpos
-
-
Constructor Details
-
Buffer
public Buffer()- See Also:
-
Buffer
-
Buffer
public Buffer(byte[] data) -
Buffer
public Buffer(int size) -
Buffer
private Buffer(byte[] data, boolean read)
-
-
Method Details
-
getNextPowerOf2
protected static int getNextPowerOf2(int i) -
array
public byte[] array() -
available
public int available() -
clear
public void clear()Resets this buffer. The object becomes ready for reuse. -
rpos
public int rpos() -
rpos
public void rpos(int rpos) -
wpos
public int wpos() -
wpos
public void wpos(int wpos) -
ensureAvailable
- Throws:
Buffer.BufferException
-
ensureCapacity
public void ensureCapacity(int capacity) -
compact
public void compact()Compact thisSSHPacket -
getCompactData
public byte[] getCompactData() -
readBoolean
Read an SSH boolean byte- Returns:
- the
trueorfalsevalue read - Throws:
Buffer.BufferException
-
putBoolean
Puts an SSH boolean value- Parameters:
b- the value- Returns:
- this
-
readByte
Read a byte from the buffer- Returns:
- the byte read
- Throws:
Buffer.BufferException
-
putByte
Writes a single byte into this buffer- Parameters:
b-- Returns:
- this
-
readBytes
Read an SSH byte-array- Returns:
- the byte-array read
- Throws:
Buffer.BufferException
-
putBytes
Writes Java byte-array as an SSH byte-array- Parameters:
b- Java byte-array- Returns:
- this
-
putBytes
Writes Java byte-array as an SSH byte-array- Parameters:
b- Java byte-arrayoff- offsetlen- length- Returns:
- this
-
readRawBytes
- Throws:
Buffer.BufferException
-
readRawBytes
- Throws:
Buffer.BufferException
-
putRawBytes
-
putRawBytes
-
putBuffer
Copies the contents of provided buffer into this buffer- Parameters:
buffer- theBufferto copy- Returns:
- this
-
readUInt32AsInt
- Throws:
Buffer.BufferException
-
readUInt32
- Throws:
Buffer.BufferException
-
putUInt32FromInt
Writes a uint32 integer- Parameters:
uint32-- Returns:
- this
-
putUInt32
Writes a uint32 integer- Parameters:
uint32-- Returns:
- this
-
readMPInt
Read an SSH multiple-precision integer- Returns:
- the MP integer as a
BigInteger - Throws:
Buffer.BufferException
-
putMPInt
-
readUInt64
- Throws:
Buffer.BufferException
-
readUInt64AsBigInteger
- Throws:
Buffer.BufferException
-
putUInt64
-
putUInt64
-
putUInt64Unchecked
-
readString
Reads an SSH string- Parameters:
cs- the charset to use for decoding- Returns:
- the string as a Java
String - Throws:
Buffer.BufferException
-
readString
Reads an SSH string usingUTF8- Returns:
- the string as a Java
String - Throws:
Buffer.BufferException
-
readStringAsBytes
Reads an SSH string- Returns:
- the string as a byte-array
- Throws:
Buffer.BufferException
-
putString
-
putString
-
putString
-
putString
-
putSensitiveString
Writes a char-array as an SSH string and then blanks it out. This is useful when a plaintext password needs to be sent. Ifstrisnull, an empty string is written.- Parameters:
str- (null-ok) the string as a character array- Returns:
- this
-
readPublicKey
- Throws:
Buffer.BufferException
-
putPublicKey
-
putSignature
-
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
-
toString
-