net.schmizz.sshj.common
Class Buffer<T extends Buffer<T>>

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

public class Buffer<T extends Buffer<T>>
extends Object


Nested Class Summary
static class Buffer.BufferException
           
static class Buffer.PlainBuffer
           
 
Field Summary
protected  byte[] data
           
static int DEFAULT_SIZE
          The default size for a Buffer (256 bytes)
static int MAX_SIZE
          The maximum valid size of buffer (i.e.
protected  int rpos
           
protected  int wpos
           
 
Constructor Summary
Buffer()
           
Buffer(Buffer<?> from)
           
Buffer(byte[] data)
           
Buffer(int size)
           
 
Method Summary
 byte[] array()
           
 int available()
           
 void clear()
          Resets this buffer.
 void compact()
          Compact this SSHPacket
protected  void ensureAvailable(int a)
           
 void ensureCapacity(int capacity)
           
 byte[] getCompactData()
           
protected static int getNextPowerOf2(int i)
           
 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)
          Writes Java byte-array as an SSH byte-array
 T putBytes(byte[] b, int off, int len)
          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(byte[] str, int offset, int len)
           
 T putString(String string)
           
 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)
           
 void readRawBytes(byte[] buf, int off, int len)
           
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SIZE

public static final int DEFAULT_SIZE
The default size for a Buffer (256 bytes)

See Also:
Constant Field Values

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:
Constant Field Values

data

protected byte[] data

rpos

protected int rpos

wpos

protected int wpos
Constructor Detail

Buffer

public Buffer()
See Also:
DEFAULT_SIZE

Buffer

public Buffer(Buffer<?> from)

Buffer

public Buffer(byte[] data)

Buffer

public Buffer(int size)
Method Detail

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

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

putUInt64

public T putUInt64(long uint64)

readString

public String readString()
                  throws Buffer.BufferException
Reads an SSH string

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)

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


Copyright © 2009-2012. All Rights Reserved.