use of java.nio.BufferUnderflowException in project robovm by robovm.
the class ByteBufferTest method testGetbyteArrayintint.
/*
* Class under test for java.nio.ByteBuffer get(byte[], int, int)
*/
public void testGetbyteArrayintint() {
buf.clear();
byte[] array = new byte[buf.capacity()];
try {
buf.get(new byte[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(array, 2, array.length);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
buf.get((byte[]) null, -1, 0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
try {
buf.get(array, 1, Integer.MAX_VALUE);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IndexOutOfBoundsException e) {
// 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();
ByteBuffer ret = buf.get(array, 0, array.length);
assertEquals(buf.position(), buf.capacity());
assertContentEquals(buf, array, 0, array.length);
assertSame(ret, buf);
}
use of java.nio.BufferUnderflowException in project robovm by robovm.
the class FloatBufferTest method testGetfloatArray.
/*
* Class under test for java.nio.FloatBuffer get(float[])
*/
public void testGetfloatArray() {
float[] array = new float[1];
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
FloatBuffer 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
}
try {
buf.position(buf.limit());
buf.get((float[]) null);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (NullPointerException e) {
// expected
}
buf.get(new float[0]);
}
use of java.nio.BufferUnderflowException in project robovm by robovm.
the class CharBufferTest method testGetcharArrayintint.
/*
* Class under test for java.nio.CharBuffer get(char[], int, int)
*/
public void testGetcharArrayintint() {
buf.clear();
char[] array = new char[buf.capacity()];
try {
buf.get(new char[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((char[]) 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();
CharBuffer ret = buf.get(array, 0, array.length);
assertEquals(buf.position(), buf.capacity());
assertContentEquals(buf, array, 0, array.length);
assertSame(ret, buf);
}
use of java.nio.BufferUnderflowException in project platform_frameworks_base by android.
the class ApkSignatureSchemeV2Verifier method verify.
/**
* Verifies the contents of the provided APK file against the provided APK Signature Scheme v2
* Block.
*
* @param signatureInfo APK Signature Scheme v2 Block and information relevant for verifying it
* against the APK file.
*/
private static X509Certificate[][] verify(FileDescriptor apkFileDescriptor, SignatureInfo signatureInfo) throws SecurityException {
int signerCount = 0;
Map<Integer, byte[]> contentDigests = new ArrayMap<>();
List<X509Certificate[]> signerCerts = new ArrayList<>();
CertificateFactory certFactory;
try {
certFactory = CertificateFactory.getInstance("X.509");
} catch (CertificateException e) {
throw new RuntimeException("Failed to obtain X.509 CertificateFactory", e);
}
ByteBuffer signers;
try {
signers = getLengthPrefixedSlice(signatureInfo.signatureBlock);
} catch (IOException e) {
throw new SecurityException("Failed to read list of signers", e);
}
while (signers.hasRemaining()) {
signerCount++;
try {
ByteBuffer signer = getLengthPrefixedSlice(signers);
X509Certificate[] certs = verifySigner(signer, contentDigests, certFactory);
signerCerts.add(certs);
} catch (IOException | BufferUnderflowException | SecurityException e) {
throw new SecurityException("Failed to parse/verify signer #" + signerCount + " block", e);
}
}
if (signerCount < 1) {
throw new SecurityException("No signers found");
}
if (contentDigests.isEmpty()) {
throw new SecurityException("No content digests found");
}
verifyIntegrity(contentDigests, apkFileDescriptor, signatureInfo.apkSigningBlockOffset, signatureInfo.centralDirOffset, signatureInfo.eocdOffset, signatureInfo.eocd);
return signerCerts.toArray(new X509Certificate[signerCerts.size()][]);
}
use of java.nio.BufferUnderflowException in project platform_frameworks_base by android.
the class IconCache method notifyIconReceived.
public void notifyIconReceived(long bssid, String fileName, byte[] iconData) {
Log.d("ZXZ", String.format("Icon '%s':%d received from %012x", fileName, iconData != null ? iconData.length : -1, bssid));
IconKey key;
HSIconFileElement iconFileElement = null;
List<OSUInfo> updates = new ArrayList<>();
LinkedList<QuerySet> querySets = mBssQueues.get(bssid);
if (querySets == null || querySets.isEmpty()) {
Log.d(OSUManager.TAG, String.format("Spurious icon response from %012x for '%s' (%d) bytes", bssid, fileName, iconData != null ? iconData.length : -1));
Log.d("ZXZ", "query set: " + querySets + ", BSS queues: " + Utils.bssidsToString(mBssQueues.keySet()));
return;
} else {
QuerySet querySet = querySets.removeFirst();
if (iconData != null) {
try {
iconFileElement = new HSIconFileElement(HSIconFile, ByteBuffer.wrap(iconData).order(ByteOrder.LITTLE_ENDIAN));
} catch (ProtocolException | BufferUnderflowException e) {
Log.e(OSUManager.TAG, "Failed to parse ANQP icon file: " + e);
}
}
key = querySet.updateIcon(fileName, iconFileElement);
if (key == null) {
Log.d(OSUManager.TAG, String.format("Spurious icon response from %012x for '%s' (%d) bytes", bssid, fileName, iconData != null ? iconData.length : -1));
Log.d("ZXZ", "query set: " + querySets + ", BSS queues: " + Utils.bssidsToString(mBssQueues.keySet()));
querySets.addFirst(querySet);
return;
}
if (iconFileElement != null) {
mCache.put(key, iconFileElement);
}
if (querySet.isEmpty()) {
mBssQueues.remove(bssid);
}
updates.add(querySet.getOsuInfo());
}
// Update any other pending entries that matches the ESS of the currently resolved icon
Iterator<Map.Entry<Long, LinkedList<QuerySet>>> bssIterator = mBssQueues.entrySet().iterator();
while (bssIterator.hasNext()) {
Map.Entry<Long, LinkedList<QuerySet>> bssEntries = bssIterator.next();
Iterator<QuerySet> querySetIterator = bssEntries.getValue().iterator();
while (querySetIterator.hasNext()) {
QuerySet querySet = querySetIterator.next();
if (querySet.updateIcon(key, iconFileElement)) {
querySetIterator.remove();
updates.add(querySet.getOsuInfo());
}
}
if (bssEntries.getValue().isEmpty()) {
bssIterator.remove();
}
}
initiateQuery(bssid);
mOSUManager.iconResults(updates);
}
Aggregations