use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testArrayOffset.
@Test
public void testArrayOffset() {
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
ByteSource bs = createByteSource(bytes);
if (bs.hasArray()) {
assertEquals(0, bs.arrayOffset());
ByteBuffer bb = ByteBuffer.wrap(bytes);
bb.position(1);
bs = ByteSourceFactory.create(bb.slice());
assertEquals(1, bs.arrayOffset());
} 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 testGetIntInt.
@Test
public void testGetIntInt() {
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);
bs.position(3);
int i = bs.getInt(0);
assertEquals(0x11102233, i);
assertEquals(3, bs.position());
i = bs.getInt(4);
assertEquals(0x22203344, i);
assertEquals(3, bs.position());
i = bs.getInt(4 * 4);
assertEquals(0x55506677, i);
assertEquals(3, bs.position());
try {
bs.getInt((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 testPosition.
@Test
public void testPosition() {
assertEquals(0, createByteSource(new byte[] {}).position());
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
assertEquals(0, bs.position());
try {
bs.position(-1);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
bs.position(11);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
assertEquals(0, bs.position());
bs.position(10);
assertEquals(10, bs.position());
bs.limit(3);
assertEquals(3, bs.position());
try {
bs.position(4);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetShort.
@Test
public void testGetShort() {
ByteBuffer bb = ByteBuffer.allocate(10);
ShortBuffer sb = bb.asShortBuffer();
sb.put((short) 0x1110);
sb.put((short) 0x2220);
sb.put((short) 0x3330);
sb.put((short) 0x4440);
sb.put((short) 0x5550);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
short s = bs.getShort();
assertEquals(0x1110, s);
assertEquals(2, bs.position());
s = bs.getShort();
assertEquals(0x2220, s);
assertEquals(4, bs.position());
bs.position(8);
s = bs.getShort();
assertEquals(0x5550, s);
assertEquals(10, bs.position());
try {
bs.getShort();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testHasArray.
@Test
public void testHasArray() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
assertEquals(!isTestOffHeap(), bs.hasArray());
}
Aggregations