Search in sources :

Example 46 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project geode by apache.

the class ByteSourceJUnitTest method testGetByteArrayIntInt.

@Test
public void testGetByteArrayIntInt() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    byte[] bytes = new byte[10];
    bs.get(bytes, 0, 2);
    assertEquals(2, bs.position());
    bs.get(bytes, 2, 0);
    assertEquals(2, bs.position());
    bs.get(bytes, 2, 3);
    assertEquals(5, bs.position());
    try {
        bs.get(bytes, 4, 6);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
    bs.get(bytes, 5, 5);
    assertEquals(10, bs.position());
    bs.get(bytes, 10, 0);
    assertEquals(10, bs.position());
    assertArrayEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, bytes);
    try {
        bs.get(bytes, 9, 1);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
    try {
        bs.get(bytes, 10, 1);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.get(bytes, 3, -1);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.get(bytes, -1, 2);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) 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 47 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project geode by apache.

the class ByteSourceJUnitTest method testGetByteArray.

@Test
public void testGetByteArray() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    byte[] bytes = new byte[2];
    bs.get(bytes);
    assertArrayEquals(new byte[] { 1, 2 }, bytes);
    assertEquals(2, bs.position());
    bytes = new byte[0];
    bs.get(bytes);
    assertEquals(2, bs.position());
    bytes = new byte[3];
    bs.get(bytes);
    assertArrayEquals(new byte[] { 3, 4, 5 }, bytes);
    assertEquals(5, bs.position());
    try {
        bytes = new byte[6];
        bs.get(bytes);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
    bytes = new byte[5];
    bs.get(bytes);
    assertArrayEquals(new byte[] { 6, 7, 8, 9, 0 }, bytes);
    assertEquals(10, bs.position());
    bytes = new byte[0];
    bs.get(bytes);
    assertEquals(10, bs.position());
    try {
        bytes = new byte[1];
        bs.get(bytes);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) 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 48 with BufferUnderflowException

use of java.nio.BufferUnderflowException 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) {
    }
}
Also used : IntBuffer(java.nio.IntBuffer) 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 49 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project geode by apache.

the class ByteSourceJUnitTest method testGet.

@Test
public void testGet() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    byte b = bs.get();
    assertEquals(1, b);
    assertEquals(1, bs.position());
    b = bs.get();
    assertEquals(2, b);
    assertEquals(2, bs.position());
    bs.position(bs.limit() - 1);
    b = bs.get();
    assertEquals(0, b);
    assertEquals(10, bs.position());
    try {
        bs.get();
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) 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 50 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project intellij-community by JetBrains.

the class Native2AsciiCharsetDecoder method decodeLoop.

@Override
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
    try {
        CoderResult coderResult = doFlush(out);
        if (coderResult == CoderResult.OVERFLOW)
            return CoderResult.OVERFLOW;
        int start = in.position();
        byte[] buf = new byte[4];
        while (in.position() < in.limit()) {
            in.mark();
            final byte b = in.get();
            if (b == '\\') {
                decodeArray(in.array(), start, in.position() - 1);
                byte next = in.get();
                if (next == 'u') {
                    buf[0] = in.get();
                    buf[1] = in.get();
                    buf[2] = in.get();
                    buf[3] = in.get();
                    char decoded = unicode(buf);
                    if (decoded == INVALID_CHAR) {
                        myOutBuffer.append("\\u");
                        myOutBuffer.append((char) buf[0]);
                        myOutBuffer.append((char) buf[1]);
                        myOutBuffer.append((char) buf[2]);
                        myOutBuffer.append((char) buf[3]);
                    } else {
                        myOutBuffer.append(decoded);
                    }
                } else {
                    myOutBuffer.append("\\");
                    myOutBuffer.append((char) next);
                }
                start = in.position();
            }
        }
        decodeArray(in.array(), start, in.position());
    } catch (BufferUnderflowException e) {
        in.reset();
    }
    return doFlush(out);
}
Also used : BufferUnderflowException(java.nio.BufferUnderflowException) CoderResult(java.nio.charset.CoderResult)

Aggregations

BufferUnderflowException (java.nio.BufferUnderflowException)123 ByteBuffer (java.nio.ByteBuffer)70 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)22 DirectByteBuffer (java.nio.DirectByteBuffer)15 Test (org.junit.Test)14 CertificateException (java.security.cert.CertificateException)12 X509Certificate (java.security.cert.X509Certificate)11 BigInteger (java.math.BigInteger)10 ByteSource (org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)9 UnitTest (org.apache.geode.test.junit.categories.UnitTest)9 CharBuffer (java.nio.CharBuffer)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FloatBuffer (java.nio.FloatBuffer)6 CertificateFactory (java.security.cert.CertificateFactory)6 HashMap (java.util.HashMap)6 ArrayMap (android.util.ArrayMap)5 HSIconFileElement (com.android.anqp.HSIconFileElement)5