use of org.jgroups.util.ByteArrayDataInputStream 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.ByteArrayDataInputStream 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.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testPosition.
public void testPosition() {
byte[] buf = new byte[100];
buf[10] = 'B';
buf[11] = 'e';
buf[12] = 'l';
buf[13] = 'a';
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf, 10, 4);
in.position(13);
try {
in.position(14);
} catch (Exception ex) {
System.out.println("caught exception as expected: " + ex);
assert ex instanceof IndexOutOfBoundsException;
}
}
use of org.jgroups.util.ByteArrayDataInputStream 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.ByteArrayDataInputStream 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