use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class PdxUnreadData method initialize.
public void initialize(UnreadPdxType unreadType, PdxReaderImpl reader) {
this.unreadType = unreadType;
int[] indexes = unreadType.getUnreadFieldIndexes();
this.unreadData = new byte[indexes.length][];
int i = 0;
for (int idx : indexes) {
ByteSource field = reader.getRaw(idx);
// Copy the unread data into a new byte array
this.unreadData[i] = new byte[field.capacity()];
field.position(0);
field.get(this.unreadData[i]);
i++;
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetInt.
@Test
public void testGetInt() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
bs.position(4);
byte b = bs.get(0);
assertEquals(1, b);
assertEquals(4, bs.position());
b = bs.get(1);
assertEquals(2, b);
assertEquals(4, bs.position());
b = bs.get(9);
assertEquals(0, b);
try {
bs.get(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 testLimit.
@Test
public void testLimit() {
assertEquals(0, createByteSource(new byte[] {}).limit());
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
assertEquals(10, bs.limit());
try {
bs.limit(11);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
try {
bs.limit(-1);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
assertEquals(10, bs.limit());
bs.limit(3);
assertEquals(3, bs.limit());
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetChar.
@Test
public void testGetChar() {
ByteBuffer bb = ByteBuffer.allocate(10);
CharBuffer cb = bb.asCharBuffer();
cb.put("abcde");
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
char c = bs.getChar();
assertEquals('a', c);
assertEquals(2, bs.position());
c = bs.getChar();
assertEquals('b', c);
assertEquals(4, bs.position());
bs.position(8);
c = bs.getChar();
assertEquals('e', c);
assertEquals(10, bs.position());
try {
bs.getChar();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.
the class ByteSourceJUnitTest method testGetShortInt.
@Test
public void testGetShortInt() {
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);
bs.position(3);
short s = bs.getShort(0);
assertEquals(0x1110, s);
assertEquals(3, bs.position());
s = bs.getShort(2);
assertEquals(0x2220, s);
assertEquals(3, bs.position());
s = bs.getShort(8);
assertEquals(0x5550, s);
assertEquals(3, bs.position());
try {
bs.getShort(9);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
Aggregations