Class Buffer<T extends Buffer<T>>

java.lang.Object
net.schmizz.sshj.common.Buffer<T>
Direct Known Subclasses:
Buffer.PlainBuffer, SFTPPacket, SSHPacket

public class Buffer<T extends Buffer<T>> extends Object
  • Field Details

    • DEFAULT_SIZE

      public static final int DEFAULT_SIZE
      The default size for a Buffer (256 bytes)
      See Also:
    • MAX_SIZE

      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)
      See Also:
    • MAX_UINT64_VALUE

      public static final BigInteger 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

      public Buffer(Buffer<?> from)
    • 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

      protected void ensureAvailable(int a) throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • ensureCapacity

      public void ensureCapacity(int capacity)
    • compact

      public void compact()
      Compact this SSHPacket
    • getCompactData

      public byte[] getCompactData()
    • readBoolean

      public boolean readBoolean() throws Buffer.BufferException
      Read an SSH boolean byte
      Returns:
      the true or false value read
      Throws:
      Buffer.BufferException
    • putBoolean

      public T putBoolean(boolean b)
      Puts an SSH boolean value
      Parameters:
      b - the value
      Returns:
      this
    • readByte

      public byte readByte() throws Buffer.BufferException
      Read a byte from the buffer
      Returns:
      the byte read
      Throws:
      Buffer.BufferException
    • putByte

      public T putByte(byte b)
      Writes a single byte into this buffer
      Parameters:
      b -
      Returns:
      this
    • readBytes

      public byte[] readBytes() throws Buffer.BufferException
      Read an SSH byte-array
      Returns:
      the byte-array read
      Throws:
      Buffer.BufferException
    • putBytes

      public T putBytes(byte[] b)
      Writes Java byte-array as an SSH byte-array
      Parameters:
      b - Java byte-array
      Returns:
      this
    • putBytes

      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
    • readRawBytes

      public void readRawBytes(byte[] buf) throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • readRawBytes

      public void readRawBytes(byte[] buf, int off, int len) throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • putRawBytes

      public T putRawBytes(byte[] d)
    • putRawBytes

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

      public T putBuffer(Buffer<? extends Buffer<?>> buffer)
      Copies the contents of provided buffer into this buffer
      Parameters:
      buffer - the Buffer to copy
      Returns:
      this
    • readUInt32AsInt

      public int readUInt32AsInt() throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • readUInt32

      public long readUInt32() throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • putUInt32FromInt

      public T putUInt32FromInt(int uint32)
      Writes a uint32 integer
      Parameters:
      uint32 -
      Returns:
      this
    • putUInt32

      public T putUInt32(long uint32)
      Writes a uint32 integer
      Parameters:
      uint32 -
      Returns:
      this
    • readMPInt

      public BigInteger readMPInt() throws Buffer.BufferException
      Read an SSH multiple-precision integer
      Returns:
      the MP integer as a BigInteger
      Throws:
      Buffer.BufferException
    • putMPInt

      public T putMPInt(BigInteger bi)
    • readUInt64

      public long readUInt64() throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • readUInt64AsBigInteger

      public BigInteger readUInt64AsBigInteger() throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • putUInt64

      public T putUInt64(long uint64)
    • putUInt64

      public T putUInt64(BigInteger uint64)
    • putUInt64Unchecked

      private T putUInt64Unchecked(long uint64)
    • readString

      public String readString(Charset cs) throws Buffer.BufferException
      Reads an SSH string
      Parameters:
      cs - the charset to use for decoding
      Returns:
      the string as a Java String
      Throws:
      Buffer.BufferException
    • readString

      public String readString() throws Buffer.BufferException
      Reads an SSH string using UTF8
      Returns:
      the string as a Java String
      Throws:
      Buffer.BufferException
    • readStringAsBytes

      public byte[] readStringAsBytes() throws Buffer.BufferException
      Reads an SSH string
      Returns:
      the string as a byte-array
      Throws:
      Buffer.BufferException
    • putString

      public T putString(byte[] str)
    • putString

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

      public T putString(String string, Charset cs)
    • putString

      public T putString(String string)
    • putSensitiveString

      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
    • readPublicKey

      public PublicKey readPublicKey() throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • putPublicKey

      public T putPublicKey(PublicKey key)
    • putSignature

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

      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
    • toString

      public String toString()
      Overrides:
      toString in class Object