Search in sources :

Example 1 with ByteSource

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++;
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)

Example 2 with ByteSource

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) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with ByteSource

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());
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with ByteSource

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) {
    }
}
Also used : CharBuffer(java.nio.CharBuffer) ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) ByteBuffer(java.nio.ByteBuffer) BufferUnderflowException(java.nio.BufferUnderflowException) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with ByteSource

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) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ByteSource (org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)33 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)29 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)29 UnitTest (org.apache.geode.test.junit.categories.UnitTest)29 Test (org.junit.Test)29 ByteBuffer (java.nio.ByteBuffer)16 BufferUnderflowException (java.nio.BufferUnderflowException)9 CharBuffer (java.nio.CharBuffer)2 DoubleBuffer (java.nio.DoubleBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 IntBuffer (java.nio.IntBuffer)2 LongBuffer (java.nio.LongBuffer)2 ShortBuffer (java.nio.ShortBuffer)2 InternalGemFireException (org.apache.geode.InternalGemFireException)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 Version (org.apache.geode.internal.Version)1