use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testBoolean.
public void testBoolean() throws Exception {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
out.writeBoolean(true);
out.writeBoolean(false);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
assert in.readBoolean();
assert !in.readBoolean();
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testOffsetAndLimit.
public void testOffsetAndLimit() {
byte[] buf = new byte[100];
buf[10] = 'B';
buf[11] = 'e';
buf[12] = 'l';
buf[13] = 'a';
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf, 10, 4);
assert in.position() == 10;
assert in.limit() == 14;
assert in.capacity() == buf.length;
byte[] tmp = new byte[4];
in.read(tmp, 0, tmp.length);
assert "Bela".equals(new String(tmp));
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testRead.
public void testRead() {
byte[] buf = { 'b', 'e', 'l', 'a' };
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf);
for (byte b : buf) assert b == in.read();
assert -1 == in.read();
in = new ByteArrayDataInputStream(buf, 2, 2);
assert in.read() == 'l';
assert in.read() == 'a';
assert -1 == in.read();
ByteBuffer buffer = ByteBuffer.wrap(buf);
System.out.println("buffer = " + buffer);
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testSkipBytes.
public void testSkipBytes() {
byte[] buf = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' };
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf);
assert in.position() == 0;
int skipped = in.skipBytes(6);
assert skipped == 6;
assert in.position() == 6;
skipped = in.skipBytes(0);
assert skipped == 0;
assert in.position() == 6;
skipped = in.skipBytes(-1);
assert skipped == 0;
assert in.position() == 6;
skipped = in.skipBytes(5);
assert skipped == 5;
assert in.position() == 11;
in.position(6);
skipped = in.skipBytes(20);
assert skipped == 5;
assert in.position() == 11;
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testByte.
public void testByte() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(Byte.MAX_VALUE * 2);
for (short i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) out.writeByte(i);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (short i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
byte read = in.readByte();
assert i == read;
}
}
Aggregations