Search in sources :

Example 56 with BufferOverflowException

use of java.nio.BufferOverflowException in project android_frameworks_base by DirtyUnicorns.

the class AndroidKeyStoreCipherSpiBase method engineUpdate.

@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
    if (input == null) {
        throw new NullPointerException("input == null");
    }
    if (output == null) {
        throw new NullPointerException("output == null");
    }
    int inputSize = input.remaining();
    byte[] outputArray;
    if (input.hasArray()) {
        outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
        input.position(input.position() + inputSize);
    } else {
        byte[] inputArray = new byte[inputSize];
        input.get(inputArray);
        outputArray = engineUpdate(inputArray, 0, inputSize);
    }
    int outputSize = (outputArray != null) ? outputArray.length : 0;
    if (outputSize > 0) {
        int outputBufferAvailable = output.remaining();
        try {
            output.put(outputArray);
        } catch (BufferOverflowException e) {
            throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
        }
    }
    return outputSize;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 57 with BufferOverflowException

use of java.nio.BufferOverflowException in project android_frameworks_base by AOSPA.

the class AndroidKeyStoreCipherSpiBase method engineUpdate.

@Override
protected final int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
    if (input == null) {
        throw new NullPointerException("input == null");
    }
    if (output == null) {
        throw new NullPointerException("output == null");
    }
    int inputSize = input.remaining();
    byte[] outputArray;
    if (input.hasArray()) {
        outputArray = engineUpdate(input.array(), input.arrayOffset() + input.position(), inputSize);
        input.position(input.position() + inputSize);
    } else {
        byte[] inputArray = new byte[inputSize];
        input.get(inputArray);
        outputArray = engineUpdate(inputArray, 0, inputSize);
    }
    int outputSize = (outputArray != null) ? outputArray.length : 0;
    if (outputSize > 0) {
        int outputBufferAvailable = output.remaining();
        try {
            output.put(outputArray);
        } catch (BufferOverflowException e) {
            throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
        }
    }
    return outputSize;
}
Also used : ShortBufferException(javax.crypto.ShortBufferException) BufferOverflowException(java.nio.BufferOverflowException)

Example 58 with BufferOverflowException

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

the class Main method basicShortTest.

/*
     * Create a buffer and fiddle with it.
     */
public static void basicShortTest() {
    ByteBuffer directBuf = ByteBuffer.allocateDirect(64);
    //ByteBuffer directBuf = ByteBuffer.allocateDirect(65);
    ShortBuffer shortBuf = directBuf.asShortBuffer();
    short[] myShorts = { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031 };
    shortBuf.position(0);
    // should work
    shortBuf.put(myShorts, 0, 32);
    shortBuf.position(0);
    // should work
    shortBuf.put(myShorts, 16, 16);
    // advance to end
    shortBuf.put(myShorts, 16, 16);
    try {
        // should fail
        shortBuf.put(myShorts, 0, 1);
        System.err.println("ERROR: out-of-bounds put succeeded\n");
    } catch (BufferOverflowException boe) {
        System.out.println("Got expected buffer overflow exception");
    }
    try {
        shortBuf.position(0);
        // should fail
        shortBuf.put(myShorts, 0, 33);
        System.err.println("ERROR: out-of-bounds put succeeded\n");
    } catch (IndexOutOfBoundsException ioobe) {
        System.out.println("Got expected out-of-bounds exception");
    }
    try {
        shortBuf.position(16);
        // should fail
        shortBuf.put(myShorts, 0, 17);
        System.err.println("ERROR: out-of-bounds put succeeded\n");
    } catch (BufferOverflowException boe) {
        System.out.println("Got expected buffer overflow exception");
    }
}
Also used : BufferOverflowException(java.nio.BufferOverflowException) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 59 with BufferOverflowException

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

the class LongBufferTest method testPutlongArray.

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

Example 60 with BufferOverflowException

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

the class LongBufferTest method testPutlong.

/*
     * Class under test for java.nio.LongBuffer put(long)
     */
public void testPutlong() {
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
        assertEquals(buf.position(), i);
        LongBuffer ret = buf.put((long) i);
        assertEquals(buf.get(i), (long) i);
        assertSame(ret, buf);
    }
    try {
        buf.put(0);
        //$NON-NLS-1$
        fail("Should throw Exception");
    } catch (BufferOverflowException e) {
    // expected
    }
}
Also used : LongBuffer(java.nio.LongBuffer) BufferOverflowException(java.nio.BufferOverflowException)

Aggregations

BufferOverflowException (java.nio.BufferOverflowException)78 ByteBuffer (java.nio.ByteBuffer)27 ShortBufferException (javax.crypto.ShortBufferException)10 CharBuffer (java.nio.CharBuffer)9 ShortBuffer (java.nio.ShortBuffer)7 Test (org.junit.Test)7 FloatBuffer (java.nio.FloatBuffer)6 IntBuffer (java.nio.IntBuffer)6 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 IpPrefix (android.net.IpPrefix)4 Inet6Address (java.net.Inet6Address)4 DoubleBuffer (java.nio.DoubleBuffer)4 LongBuffer (java.nio.LongBuffer)4 MappedByteBuffer (java.nio.MappedByteBuffer)4 Pointer (com.cetsoft.imcache.offheap.bytebuffer.Pointer)2 EOFException (java.io.EOFException)2 CoderResult (java.nio.charset.CoderResult)2 JSONObject (org.json_voltpatches.JSONObject)2