use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetFloatInt.
@Test
public void testGetFloatInt() {
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);
bs.position(3);
float f = bs.getFloat(0);
assertEquals(1.1f, f, 0.0001);
assertEquals(3, bs.position());
f = bs.getFloat(4);
assertEquals(2.2f, f, 0.0001);
assertEquals(3, bs.position());
f = bs.getFloat(4 * 4);
assertEquals(5.5f, f, 0.0001);
assertEquals(3, bs.position());
try {
bs.getFloat((4 * 4) + 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 testGetInt1.
@Test
public void testGetInt1() {
ByteBuffer bb = ByteBuffer.allocate(20);
IntBuffer ib = bb.asIntBuffer();
ib.put(0x11102233);
ib.put(0x22203344);
ib.put(0x33304455);
ib.put(0x44405566);
ib.put(0x55506677);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
int i = bs.getInt();
assertEquals(0x11102233, i);
assertEquals(4, bs.position());
i = bs.getInt();
assertEquals(0x22203344, i);
assertEquals(8, bs.position());
bs.position(4 * 4);
i = bs.getInt();
assertEquals(0x55506677, i);
assertEquals(20, bs.position());
try {
bs.getInt();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetCharInt.
@Test
public void testGetCharInt() {
ByteBuffer bb = ByteBuffer.allocate(10);
CharBuffer cb = bb.asCharBuffer();
cb.put("abcde");
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
bs.position(3);
char c = bs.getChar(0);
assertEquals('a', c);
assertEquals(3, bs.position());
c = bs.getChar(2);
assertEquals('b', c);
assertEquals(3, bs.position());
c = bs.getChar(8);
assertEquals('e', c);
assertEquals(3, bs.position());
try {
bs.getChar(10);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testArray.
@Test
public void testArray() {
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
ByteSource bs = createByteSource(bytes);
if (bs.hasArray()) {
assertEquals(bytes, bs.array());
ByteBuffer bb = ByteBuffer.wrap(bytes);
bb.position(1);
bs = ByteSourceFactory.create(bb.slice());
assertEquals(bytes, bs.array());
} else {
try {
bs.array();
fail("expected UnsupportedOperationException");
} catch (UnsupportedOperationException expected) {
}
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testDuplicate.
@Test
public void testDuplicate() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
ByteSource dup = bs.duplicate();
assertEquals(bs, dup);
dup.position(1);
assertNotEquals(bs, dup);
dup.position(0);
assertEquals(bs, dup);
dup.limit(2);
assertNotEquals(bs, dup);
dup.limit(bs.limit());
assertEquals(bs, dup);
if (bs.hasArray()) {
byte[] bsBytes = bs.array();
byte[] dupBytes = dup.array();
assertEquals(bsBytes, dupBytes);
assertNotEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, dupBytes);
}
bs.position(1);
bs.limit(2);
ByteSource dup2 = bs.duplicate();
assertEquals(bs, dup2);
assertEquals(1, dup2.position());
assertEquals(2, dup2.limit());
}
Aggregations