Search in sources :

Example 1 with IndexOutOfBoundsException

use of java.lang.IndexOutOfBoundsException in project translationstudio8 by heartsome.

the class FastIntBuffer method getIntArray.

/**
 * Returns a single int array representing every int in this buffer instance
 * @return int[]  (null if there isn't anything left in the buffer   
 * @param startingOffset int
 * @param len int
 * @return int[]
 */
public int[] getIntArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }
    // allocate result array
    int[] result = new int[len];
    //    int first_index = (int) (startingOffset / pageSize);
    //    int last_index = (int) ((startingOffset + len) / pageSize);
    //    if ((startingOffset + len) % pageSize == 0) {
    //        last_index--;
    //    }
    int first_index = startingOffset >> exp;
    int last_index = (startingOffset + len) >> exp;
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }
    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy((int[]) (bufferArrayList.get(first_index)), //            startingOffset % pageSize,
        startingOffset & r, result, 0, len);
    } else {
        int int_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            int[] currentChunk = (int[]) bufferArrayList.get(i);
            if (// first section
            i == first_index) {
                System.arraycopy(currentChunk, //                  startingOffset % pageSize,
                startingOffset & r, result, 0, //                  pageSize - (startingOffset % pageSize));
                pageSize - (startingOffset & r));
                //                int_array_offset += pageSize - (startingOffset) % pageSize;
                int_array_offset += pageSize - (startingOffset & r);
            } else if (// last sections
            i == last_index) {
                System.arraycopy(currentChunk, 0, result, int_array_offset, len - int_array_offset);
            } else {
                System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
                int_array_offset += pageSize;
            }
        }
    }
    return result;
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException)

Example 2 with IndexOutOfBoundsException

use of java.lang.IndexOutOfBoundsException in project translationstudio8 by heartsome.

the class FastLongBuffer method getLongArray.

/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }
    // allocate result array
    long[] result = new long[len];
    int first_index = (startingOffset >> exp);
    int last_index = ((startingOffset + len) >> exp);
    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }
    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy((long[]) (bufferArrayList.oa[first_index]), //            startingOffset % pageSize,
        startingOffset & r, result, 0, len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.oa[i];
            if (// first section
            i == first_index) {
                System.arraycopy(currentChunk, //                  startingOffset % pageSize,
                startingOffset & r, result, 0, //                  pageSize - (startingOffset % r));
                pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (// last sections
            i == last_index) {
                System.arraycopy(currentChunk, 0, result, long_array_offset, len - long_array_offset);
            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }
    return result;
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException)

Example 3 with IndexOutOfBoundsException

use of java.lang.IndexOutOfBoundsException in project translationstudio8 by heartsome.

the class FastLongBuffer method getLongArray.

/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size()) {
        throw (new IndexOutOfBoundsException());
    }
    // allocate result array
    long[] result = new long[len];
    int first_index = (startingOffset >> exp);
    int last_index = ((startingOffset + len) >> exp);
    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }
    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy((long[]) (bufferArrayList.get(first_index)), //            startingOffset % pageSize,
        startingOffset & r, result, 0, len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.get(i);
            if (// first section
            i == first_index) {
                System.arraycopy(currentChunk, //                  startingOffset % pageSize,
                startingOffset & r, result, 0, //                  pageSize - (startingOffset % r));
                pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (// last sections
            i == last_index) {
                System.arraycopy(currentChunk, 0, result, long_array_offset, len - long_array_offset);
            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }
    return result;
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException)

Example 4 with IndexOutOfBoundsException

use of java.lang.IndexOutOfBoundsException in project android_frameworks_opt_telephony by LineageOS.

the class UiccPkcs15 method parseAcrf.

// parse ACRF file to get file id for ACCF file
// data is hex string, return file id if parse success, null otherwise
private String parseAcrf(String data) {
    String ret = null;
    String acRules = data;
    while (!acRules.isEmpty()) {
        TLV tlvRule = new TLV(TAG_ASN_SEQUENCE);
        try {
            acRules = tlvRule.parse(acRules, false);
            String ruleString = tlvRule.getValue();
            if (ruleString.startsWith(TAG_TARGET_AID)) {
                // rule string consists of target AID + path, example:
                // [A0] 08 [04] 06 FF FF FF FF FF FF [30] 04 [04] 02 43 10
                // bytes in [] are tags for the data
                // A0
                TLV tlvTarget = new TLV(TAG_TARGET_AID);
                // 04
                TLV tlvAid = new TLV(TAG_ASN_OCTET_STRING);
                // 30
                TLV tlvAsnPath = new TLV(TAG_ASN_SEQUENCE);
                // 04
                TLV tlvPath = new TLV(TAG_ASN_OCTET_STRING);
                // populate tlvTarget.value with aid data,
                // ruleString has remaining data for path
                ruleString = tlvTarget.parse(ruleString, false);
                // parse tlvTarget.value to get actual strings for AID.
                // no other tags expected so shouldConsumeAll is true.
                tlvAid.parse(tlvTarget.getValue(), true);
                if (CARRIER_RULE_AID.equals(tlvAid.getValue())) {
                    tlvAsnPath.parse(ruleString, true);
                    tlvPath.parse(tlvAsnPath.getValue(), true);
                    ret = tlvPath.getValue();
                }
            }
            // skip current rule as it doesn't have expected TAG
            continue;
        } catch (IllegalArgumentException | IndexOutOfBoundsException ex) {
            log("Error: " + ex);
            // Bad data, ignore all remaining ACRules
            break;
        }
    }
    return ret;
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException) TLV(com.android.internal.telephony.uicc.UiccCarrierPrivilegeRules.TLV)

Example 5 with IndexOutOfBoundsException

use of java.lang.IndexOutOfBoundsException in project android_frameworks_opt_telephony by LineageOS.

the class UiccPkcs15 method parseAccf.

// parse ACCF and add to mRules
private void parseAccf(String data) {
    String acCondition = data;
    while (!acCondition.isEmpty()) {
        TLV tlvCondition = new TLV(TAG_ASN_SEQUENCE);
        TLV tlvCert = new TLV(TAG_ASN_OCTET_STRING);
        try {
            acCondition = tlvCondition.parse(acCondition, false);
            tlvCert.parse(tlvCondition.getValue(), true);
            if (!tlvCert.getValue().isEmpty()) {
                mRules.add(tlvCert.getValue());
            }
        } catch (IllegalArgumentException | IndexOutOfBoundsException ex) {
            log("Error: " + ex);
            // Bad data, ignore all remaining acCondition data
            break;
        }
    }
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException) TLV(com.android.internal.telephony.uicc.UiccCarrierPrivilegeRules.TLV)

Aggregations

IllegalArgumentException (java.lang.IllegalArgumentException)6 IndexOutOfBoundsException (java.lang.IndexOutOfBoundsException)6 TLV (com.android.internal.telephony.uicc.UiccCarrierPrivilegeRules.TLV)2