use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetDoubleInt.
@Test
public void testGetDoubleInt() {
ByteBuffer bb = ByteBuffer.allocate(40);
DoubleBuffer db = bb.asDoubleBuffer();
db.put(1.1d);
db.put(2.2d);
db.put(3.3d);
db.put(4.4d);
db.put(5.5d);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
bs.position(3);
double d = bs.getDouble(0);
assertEquals(1.1d, d, 0.0001);
assertEquals(3, bs.position());
d = bs.getDouble(8);
assertEquals(2.2d, d, 0.0001);
assertEquals(3, bs.position());
d = bs.getDouble(4 * 8);
assertEquals(5.5d, d, 0.0001);
assertEquals(3, bs.position());
try {
bs.getDouble((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 testSendToDataOutput.
@Test
public void testSendToDataOutput() throws IOException {
HeapDataOutputStream hdos = new HeapDataOutputStream((Version) null);
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
bs.sendTo(hdos);
assertEquals(0, bs.remaining());
ByteBuffer bb = hdos.toByteBuffer();
assertEquals(10, bb.limit());
assertEquals(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }), bb);
bs.position(1);
bs.limit(9);
hdos = new HeapDataOutputStream((Version) null);
bs.sendTo(hdos);
assertEquals(0, bs.remaining());
bb = hdos.toByteBuffer();
assertEquals(8, bb.limit());
assertEquals(ByteBuffer.wrap(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }), bb);
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testSliceInt.
@Test
public void testSliceInt() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
bs.position(1);
try {
bs.slice(10);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
bs.slice(-1);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
assertEquals(0, bs.slice(0).remaining());
ByteSource slice = bs.slice(2);
assertEquals(createByteSource(new byte[] { 2, 3 }), slice);
assertEquals(0, slice.position());
assertEquals(2, slice.limit());
slice.position(1);
slice.limit(1);
assertEquals(1, bs.position());
assertEquals(10, bs.limit());
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetFloat.
@Test
public void testGetFloat() {
ByteBuffer bb = ByteBuffer.allocate(20);
FloatBuffer fb = bb.asFloatBuffer();
fb.put(1.1f);
fb.put(2.2f);
fb.put(3.3f);
fb.put(4.4f);
fb.put(5.5f);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
float f = bs.getFloat();
assertEquals(1.1f, f, 0.0001);
assertEquals(4, bs.position());
f = bs.getFloat();
assertEquals(2.2f, f, 0.0001);
assertEquals(8, bs.position());
bs.position(4 * 4);
f = bs.getFloat();
assertEquals(5.5f, f, 0.0001);
assertEquals(20, bs.position());
try {
bs.getFloat();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testSendToByteBuffer.
@Test
public void testSendToByteBuffer() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
ByteBuffer bb = ByteBuffer.allocate(10);
bs.sendTo(bb);
assertEquals(0, bs.remaining());
assertEquals(10, bb.position());
bb.position(0);
assertEquals(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }), bb);
bs.position(1);
bs.limit(9);
bb = ByteBuffer.allocate(8);
bs.sendTo(bb);
assertEquals(0, bs.remaining());
assertEquals(8, bb.position());
bb.position(0);
assertEquals(ByteBuffer.wrap(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }), bb);
}
Aggregations