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;
}
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;
}
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");
}
}
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
}
}
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
}
}
Aggregations