Search in sources :

Example 21 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project robovm by robovm.

the class CharBufferTest method testGetcharArray.

/*
	 * Class under test for java.nio.CharBuffer get(char[])
	 */
public void testGetcharArray() {
    char[] array = new char[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        CharBuffer ret = buf.get(array);
        assertEquals(array[0], buf.get(i));
        assertSame(ret, buf);
    }
    try {
        buf.get(array);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException e) {
    // expected
    }
}
Also used : CharBuffer(java.nio.CharBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 22 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project robovm by robovm.

the class DoubleBufferTest method testGetdoubleArrayintint.

/*
     * Class under test for java.nio.DoubleBuffer get(double[], int, int)
     */
public void testGetdoubleArrayintint() {
    buf.clear();
    double[] array = new double[buf.capacity()];
    try {
        buf.get(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    try {
        buf.get(array, -1, array.length);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    buf.get(array, array.length, 0);
    try {
        buf.get(array, array.length + 1, 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    try {
        buf.get(array, 2, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.get((double[]) null, 0, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        buf.get(array, 2, array.length);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.get(array, 1, Integer.MAX_VALUE);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        buf.get(array, Integer.MAX_VALUE, 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    buf.clear();
    DoubleBuffer ret = buf.get(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 23 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project robovm by robovm.

the class DoubleBufferTest method testGetdoubleArray.

/*
     * Class under test for java.nio.DoubleBuffer get(double[])
     */
public void testGetdoubleArray() {
    double[] array = new double[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        DoubleBuffer ret = buf.get(array);
        assertEquals(array[0], buf.get(i), 0.01);
        assertSame(ret, buf);
    }
    try {
        buf.get(array);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException e) {
    // expected
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 24 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project robovm by robovm.

the class FloatBufferTest method testGetfloatArrayintint.

/*
     * Class under test for java.nio.FloatBuffer get(float[], int, int)
     */
public void testGetfloatArrayintint() {
    buf.clear();
    float[] array = new float[buf.capacity()];
    try {
        buf.get(new float[buf.capacity() + 1], 0, buf.capacity() + 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    try {
        buf.get(array, -1, array.length);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    buf.get(array, array.length, 0);
    try {
        buf.get(array, array.length + 1, 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    try {
        buf.get(array, 2, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.get((float[]) null, 2, -1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        buf.get(array, 2, array.length);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        buf.get(array, 1, Integer.MAX_VALUE);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferUnderflowException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        buf.get(array, Integer.MAX_VALUE, 1);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    assertEquals(buf.position(), 0);
    buf.clear();
    FloatBuffer ret = buf.get(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
}
Also used : FloatBuffer(java.nio.FloatBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 25 with BufferUnderflowException

use of java.nio.BufferUnderflowException in project platform_frameworks_base by android.

the class ApkSignatureSchemeV2Verifier method getByteBuffer.

/**
     * Relative <em>get</em> method for reading {@code size} number of bytes from the current
     * position of this buffer.
     *
     * <p>This method reads the next {@code size} bytes at this buffer's current position,
     * returning them as a {@code ByteBuffer} with start set to 0, limit and capacity set to
     * {@code size}, byte order set to this buffer's byte order; and then increments the position by
     * {@code size}.
     */
private static ByteBuffer getByteBuffer(ByteBuffer source, int size) throws BufferUnderflowException {
    if (size < 0) {
        throw new IllegalArgumentException("size: " + size);
    }
    int originalLimit = source.limit();
    int position = source.position();
    int limit = position + size;
    if ((limit < position) || (limit > originalLimit)) {
        throw new BufferUnderflowException();
    }
    source.limit(limit);
    try {
        ByteBuffer result = source.slice();
        result.order(source.order());
        source.position(limit);
        return result;
    } finally {
        source.limit(originalLimit);
    }
}
Also used : DirectByteBuffer(java.nio.DirectByteBuffer) ByteBuffer(java.nio.ByteBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

BufferUnderflowException (java.nio.BufferUnderflowException)121 ByteBuffer (java.nio.ByteBuffer)69 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