public class Buffer extends Object
The Buffer maintains a current index (from where on the put methods write, updating it on the way) and an offset. The offset is used by the get methods to read (and they update the offset, too). If a buffer is used for both reading and writing, the index should normally be bigger than the offset. Initially both are 0.
Constructor and Description |
---|
Buffer()
Creates a buffer with a default size of 20 KB.
|
Buffer(byte[] buffer)
Creates a buffer using the given array as backing store.
|
Buffer(int size)
creates a Buffer with given size.
|
Modifier and Type | Method and Description |
---|---|
int |
getByte()
reads a (unsigned) byte from the buffer.
|
void |
getByte(byte[] foo)
reads some byte from the buffer.
|
int |
getByte(int len)
ignores
len bytes in the buffer. |
int |
getInt()
reads a signed 32-bit number from the buffer.
|
int |
getLength()
calculates the length of this buffer, which is
the difference between index and offset.
|
long |
getLong()
reads a 64-bit number from the buffer.
|
byte[] |
getMPInt()
reads a multiple-precision (signed) integer.
|
byte[] |
getMPIntBits()
reads a multiple precision signed integer
as unsigned (i.e. the highest-order bit is
guaranteed to be 0).
|
int |
getOffSet()
returns the current offset.
|
byte[] |
getString()
reads a string.
|
long |
getUInt()
reads an unsigned 32-bit number from the buffer.
|
void |
putByte(byte foo)
puts one byte into the buffer.
|
void |
putByte(byte[] foo)
puts all bytes in the given byte array in the buffer.
|
void |
putByte(byte[] foo,
int begin,
int length)
puts a subsequence of the given byte array in the buffer.
|
void |
putInt(int val)
Puts a 32-bit number as 4 bytes into the buffer.
|
void |
putLong(long val)
Puts a 64-bit number as 8 bytes into the buffer.
|
void |
putMPInt(byte[] foo)
Puts a byte[] as an unsigned multiple precision integer (mpint).
|
void |
putString(byte[] foo)
puts a byte sequence formatted as a SSH string into the buffer.
|
void |
putString(byte[] foo,
int begin,
int length)
puts a byte sequence formatted as a SSH string into the buffer.
|
void |
reset()
resets index and offset.
|
void |
setOffSet(int s)
changes the current offset.
|
void |
shift()
Shifts the contents between offset and index
back to the start of the buffer, and then sets
these two values accordingly.
|
public Buffer(int size)
public Buffer(byte[] buffer)
public Buffer()
public void putByte(byte foo)
public void putByte(byte[] foo)
putBytes
, really.)public void putByte(byte[] foo, int begin, int length)
putBytes
, really.)public void putString(byte[] foo)
putString(byte[], int, int)
public void putString(byte[] foo, int begin, int length)
foo
- the array from which we take the data.begin
- the start of the data in the array.length
- how many bytes to put.public void putInt(int val)
public void putLong(long val)
public void putMPInt(byte[] foo)
public int getLength()
public int getOffSet()
public void setOffSet(int s)
s
- the new offset.public long getLong()
putLong(long)
public int getInt()
public long getUInt()
public int getByte()
public void getByte(byte[] foo)
foo
- the array to put the bytes to. This array will
be filled, i.e. we read foo.length bytes from the buffer.public int getByte(int len)
len
bytes in the buffer.
This simply sets the offset forward by len
bytes.
This is now only used in getString(int[],int[])
, and
could maybe be non-public. Or at least be named something else.
skip
would be a nice name, but this is already used
for the same method for {@code index}.
public byte[] getMPInt()
putMPInt(byte[])
public byte[] getMPIntBits()
public byte[] getString()
putString(byte[])
public void reset()
public void shift()
This is an inofficial Javadoc created by PaĆlo Ebermann. Have a look at the official homepage.