| Method from com.sshtools.j2ssh.io.ByteArrayWriter Detail: |
public static byte[] encodeInt(int i) {
byte[] raw = new byte[4];
raw[0] = (byte) (i > > 24);
raw[1] = (byte) (i > > 16);
raw[2] = (byte) (i > > 8);
raw[3] = (byte) (i);
return raw;
}
|
public void writeBigInteger(BigInteger bi) throws IOException {
byte[] raw = bi.toByteArray();
writeInt(raw.length);
write(raw);
}
|
public void writeBinaryString(byte[] data) throws IOException {
writeInt(data.length);
write(data);
}
|
public void writeBoolean(boolean b) throws IOException {
write(b ? 1 : 0);
}
|
public void writeInt(long i) throws IOException {
byte[] raw = new byte[4];
raw[0] = (byte) (i > > 24);
raw[1] = (byte) (i > > 16);
raw[2] = (byte) (i > > 8);
raw[3] = (byte) (i);
write(raw);
}
|
public void writeInt(int i) throws IOException {
byte[] raw = new byte[4];
raw[0] = (byte) (i > > 24);
raw[1] = (byte) (i > > 16);
raw[2] = (byte) (i > > 8);
raw[3] = (byte) (i);
write(raw);
}
|
public static void writeIntToArray(byte[] array,
int pos,
int value) throws IOException {
if ((array.length - pos) < 4) {
throw new IOException(
"Not enough data in array to write integer at position " +
String.valueOf(pos));
}
array[pos] = (byte) (value > > 24);
array[pos + 1] = (byte) (value > > 16);
array[pos + 2] = (byte) (value > > 8);
array[pos + 3] = (byte) (value);
}
|
public void writeString(String str) throws IOException {
if (str == null) {
writeInt(0);
} else {
/*
writeInt(str.length());
// don't use US-ASCII by default!
write(str.getBytes());
*/
// patch as of version 0.2.9
// for UTF-8 length of string is not necessarily
// equal to number of bytes
byte[] strBytes = str.getBytes();
writeInt(strBytes.length);
write(strBytes);
}
}
|
public void writeUINT32(UnsignedInteger32 value) throws IOException {
writeInt(value.longValue());
}
|
public void writeUINT64(UnsignedInteger64 value) throws IOException {
byte[] raw = new byte[8];
byte[] bi = value.bigIntValue().toByteArray();
System.arraycopy(bi, 0, raw, raw.length - bi.length, bi.length);
// Pad the raw data
write(raw);
}
|