use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetLongInt.
@Test
public void testGetLongInt() {
ByteBuffer bb = ByteBuffer.allocate(40);
LongBuffer lb = bb.asLongBuffer();
lb.put(0x1110223344556677L);
lb.put(0x2220334455667788L);
lb.put(0x3330445566778899L);
lb.put(0x4440556677889900L);
lb.put(0x55506677889900AAL);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
bs.position(3);
long l = bs.getLong(0);
assertEquals(0x1110223344556677L, l);
assertEquals(3, bs.position());
l = bs.getLong(8);
assertEquals(0x2220334455667788L, l);
assertEquals(3, bs.position());
l = bs.getLong(4 * 8);
assertEquals(0x55506677889900AAL, l);
assertEquals(3, bs.position());
try {
bs.getLong((4 * 8) + 1);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testRemaining.
@Test
public void testRemaining() {
assertEquals(0, createByteSource(new byte[] {}).remaining());
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
assertEquals(10, bs.remaining());
bs.position(1);
assertEquals(9, bs.remaining());
bs.limit(9);
assertEquals(8, bs.remaining());
bs.position(8);
assertEquals(1, bs.remaining());
bs.position(9);
assertEquals(0, bs.remaining());
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testSliceIntInt.
@Test
public void testSliceIntInt() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
try {
bs.slice(-1, 9);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
bs.slice(0, 11);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
assertEquals(bs, bs.slice(0, 10));
ByteSource slice = bs.slice(1, 9);
assertEquals(createByteSource(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }), slice);
}
Aggregations