use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testExpanding.
public void testExpanding() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1);
for (int i = 'A'; i < 'A' + 20; i++) out.write(i);
assert out.position() == 20;
byte[] buffer = new byte[20];
for (int i = 0; i < 5; i++) out.write(buffer);
assert out.position() == 120;
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testLong.
public void testLong() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
long[] numbers = { Long.MIN_VALUE, -322649, -500, 0, 1, 100, 322649, Long.MAX_VALUE };
for (long i : numbers) out.writeLong(i);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (long i : numbers) {
long num = in.readLong();
assert num == i;
}
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testWriteBytes.
public void testWriteBytes() {
String name = "Bela";
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
out.writeBytes(name);
assert out.position() == name.length();
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
byte[] tmp = new byte[name.length()];
int read = in.read(tmp, 0, tmp.length);
assert read == name.length();
assert name.equals(new String(tmp));
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testWriteChars.
public void testWriteChars() throws IOException {
String name = "Bela";
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
out.writeChars(name);
assert out.position() == name.length() * 2;
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
char[] tmp = new char[name.length()];
for (int i = 0; i < name.length(); i++) tmp[i] = in.readChar();
assert name.equals(new String(tmp));
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testShort.
public void testShort() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(Short.MAX_VALUE * 4 + 10);
for (int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) out.writeShort(i);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) {
short read = in.readShort();
assert i == read;
}
}
Aggregations