use of java.nio.BufferOverflowException in project robovm by robovm.
the class DoubleBufferTest method testPutdoubleArray.
/*
* Class under test for java.nio.DoubleBuffer put(double[])
*/
public void testPutdoubleArray() {
double[] array = new double[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
array[0] = (double) i;
DoubleBuffer ret = buf.put(array);
assertEquals(buf.get(i), (double) i, 0.0);
assertSame(ret, buf);
}
try {
buf.put(array);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
}
use of java.nio.BufferOverflowException in project robovm by robovm.
the class FloatBufferTest method testPutfloat.
/*
* Class under test for java.nio.FloatBuffer put(float)
*/
public void testPutfloat() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
FloatBuffer ret = buf.put((float) i);
assertEquals(buf.get(i), (float) i, 0.0);
assertSame(ret, buf);
}
try {
buf.put(0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
}
use of java.nio.BufferOverflowException in project robovm by robovm.
the class ShortBufferTest method testPutshortArrayintint.
/*
* Class under test for java.nio.ShortBuffer put(short[], int, int)
*/
public void testPutshortArrayintint() {
buf.clear();
short[] array = new short[buf.capacity()];
try {
buf.put(new short[buf.capacity() + 1], 0, buf.capacity() + 1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
assertEquals(buf.position(), 0);
try {
buf.put(array, -1, array.length);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, array.length + 1, 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
buf.put(array, array.length, 0);
assertEquals(buf.position(), 0);
try {
buf.put(array, 0, -1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put((short[]) null, 0, -1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
try {
buf.put(array, 2, array.length);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, Integer.MAX_VALUE, 1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.put(array, 1, Integer.MAX_VALUE);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException expected) {
} catch (IndexOutOfBoundsException expected) {
}
assertEquals(buf.position(), 0);
loadTestData2(array, 0, array.length);
ShortBuffer ret = buf.put(array, 0, array.length);
assertEquals(buf.position(), buf.capacity());
assertContentEquals(buf, array, 0, array.length);
assertSame(ret, buf);
}
use of java.nio.BufferOverflowException in project robovm by robovm.
the class ShortBufferTest method testPutshortArray.
/*
* Class under test for java.nio.ShortBuffer put(short[])
*/
public void testPutshortArray() {
short[] array = new short[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
array[0] = (short) i;
ShortBuffer ret = buf.put(array);
assertEquals(buf.get(i), (short) 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((short[]) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
}
use of java.nio.BufferOverflowException in project android_frameworks_base by crdroidandroid.
the class RouterAdvertisementDaemon method assembleRaLocked.
private void assembleRaLocked() {
final ByteBuffer ra = ByteBuffer.wrap(mRA);
ra.order(ByteOrder.BIG_ENDIAN);
boolean shouldSendRA = false;
try {
putHeader(ra, mRaParams != null && mRaParams.hasDefaultRoute);
putSlla(ra, mHwAddr);
mRaLength = ra.position();
if (mRaParams != null) {
putMtu(ra, mRaParams.mtu);
mRaLength = ra.position();
for (IpPrefix ipp : mRaParams.prefixes) {
putPio(ra, ipp, DEFAULT_LIFETIME, DEFAULT_LIFETIME);
mRaLength = ra.position();
shouldSendRA = true;
}
if (mRaParams.dnses.size() > 0) {
putRdnss(ra, mRaParams.dnses, DEFAULT_LIFETIME);
mRaLength = ra.position();
shouldSendRA = true;
}
}
for (IpPrefix ipp : mDeprecatedInfoTracker.getPrefixes()) {
putPio(ra, ipp, 0, 0);
mRaLength = ra.position();
shouldSendRA = true;
}
final Set<Inet6Address> deprecatedDnses = mDeprecatedInfoTracker.getDnses();
if (!deprecatedDnses.isEmpty()) {
putRdnss(ra, deprecatedDnses, 0);
mRaLength = ra.position();
shouldSendRA = true;
}
} catch (BufferOverflowException e) {
// The packet up to mRaLength is valid, since it has been updated
// progressively as the RA was built. Log an error, and continue
// on as best as possible.
Log.e(TAG, "Could not construct new RA: " + e);
}
// We have nothing worth announcing; indicate as much to maybeSendRA().
if (!shouldSendRA) {
mRaLength = 0;
}
}
Aggregations