Search in sources :

Example 31 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project platform_frameworks_base by android.

the class BitwiseStreamsTest method testExpandArray.

@SmallTest
public void testExpandArray() throws Exception {
    Random random = new Random();
    int iterations = 10000;
    int[] sizeArr = new int[iterations];
    int[] valueArr = new int[iterations];
    BitwiseOutputStream outStream = new BitwiseOutputStream(8);
    for (int i = 0; i < iterations; i++) {
        int x = random.nextInt();
        int size = (x & 0x07) + 1;
        int value = x & (-1 >>> (32 - size));
        sizeArr[i] = size;
        valueArr[i] = value;
        outStream.write(size, value);
    }
    BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
    for (int i = 0; i < iterations; i++) {
        assertEquals(valueArr[i], inStream.read(sizeArr[i]));
    }
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) Random(java.util.Random) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 32 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project XobotOS by xamarin.

the class BearerData method encode7bitAscii.

private static byte[] encode7bitAscii(String msg, boolean force) throws CodingException {
    try {
        BitwiseOutputStream outStream = new BitwiseOutputStream(msg.length());
        int msgLen = msg.length();
        for (int i = 0; i < msgLen; i++) {
            int charCode = UserData.charToAscii.get(msg.charAt(i), -1);
            if (charCode == -1) {
                if (force) {
                    outStream.write(7, UserData.UNENCODABLE_7_BIT_CHAR);
                } else {
                    throw new CodingException("cannot ASCII encode (" + msg.charAt(i) + ")");
                }
            } else {
                outStream.write(7, charCode);
            }
        }
        return outStream.toByteArray();
    } catch (BitwiseOutputStream.AccessException ex) {
        throw new CodingException("7bit ASCII encode failed: " + ex);
    }
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream)

Example 33 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project XobotOS by xamarin.

the class BearerData method encode.

/**
     * Create serialized representation for BearerData object.
     * (See 3GPP2 C.R1001-F, v1.0, section 4.5 for layout details)
     *
     * @param bData an instance of BearerData.
     *
     * @return byte array of raw encoded SMS bearer data.
     */
public static byte[] encode(BearerData bData) {
    bData.hasUserDataHeader = ((bData.userData != null) && (bData.userData.userDataHeader != null));
    try {
        BitwiseOutputStream outStream = new BitwiseOutputStream(200);
        outStream.write(8, SUBPARAM_MESSAGE_IDENTIFIER);
        encodeMessageId(bData, outStream);
        if (bData.userData != null) {
            outStream.write(8, SUBPARAM_USER_DATA);
            encodeUserData(bData, outStream);
        }
        if (bData.callbackNumber != null) {
            outStream.write(8, SUBPARAM_CALLBACK_NUMBER);
            encodeCallbackNumber(bData, outStream);
        }
        if (bData.userAckReq || bData.deliveryAckReq || bData.readAckReq || bData.reportReq) {
            outStream.write(8, SUBPARAM_REPLY_OPTION);
            encodeReplyOption(bData, outStream);
        }
        if (bData.numberOfMessages != 0) {
            outStream.write(8, SUBPARAM_NUMBER_OF_MESSAGES);
            encodeMsgCount(bData, outStream);
        }
        if (bData.validityPeriodRelativeSet) {
            outStream.write(8, SUBPARAM_VALIDITY_PERIOD_RELATIVE);
            encodeValidityPeriodRel(bData, outStream);
        }
        if (bData.privacyIndicatorSet) {
            outStream.write(8, SUBPARAM_PRIVACY_INDICATOR);
            encodePrivacyIndicator(bData, outStream);
        }
        if (bData.languageIndicatorSet) {
            outStream.write(8, SUBPARAM_LANGUAGE_INDICATOR);
            encodeLanguageIndicator(bData, outStream);
        }
        if (bData.displayModeSet) {
            outStream.write(8, SUBPARAM_MESSAGE_DISPLAY_MODE);
            encodeDisplayMode(bData, outStream);
        }
        if (bData.priorityIndicatorSet) {
            outStream.write(8, SUBPARAM_PRIORITY_INDICATOR);
            encodePriorityIndicator(bData, outStream);
        }
        if (bData.alertIndicatorSet) {
            outStream.write(8, SUBPARAM_ALERT_ON_MESSAGE_DELIVERY);
            encodeMsgDeliveryAlert(bData, outStream);
        }
        if (bData.messageStatusSet) {
            outStream.write(8, SUBPARAM_MESSAGE_STATUS);
            encodeMsgStatus(bData, outStream);
        }
        return outStream.toByteArray();
    } catch (BitwiseOutputStream.AccessException ex) {
        Log.e(LOG_TAG, "BearerData encode failed: " + ex);
    } catch (CodingException ex) {
        Log.e(LOG_TAG, "BearerData encode failed: " + ex);
    }
    return null;
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream)

Example 34 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_base by DirtyUnicorns.

the class BitwiseStreamsTest method testThree.

@SmallTest
public void testThree() throws Exception {
    int offset = 4;
    byte[] inBuf = HexDump.hexStringToByteArray("00031040900112488ea794e0");
    BitwiseOutputStream outStream = new BitwiseOutputStream(30);
    outStream.skip(offset);
    for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
    BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
    inStream.skip(offset);
    byte[] inBufDup = new byte[inBuf.length];
    for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
    assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 35 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_base by DirtyUnicorns.

the class BitwiseStreamsTest method testOne.

@SmallTest
public void testOne() throws Exception {
    int offset = 3;
    byte[] inBuf = HexDump.hexStringToByteArray("FFDD");
    BitwiseOutputStream outStream = new BitwiseOutputStream(30);
    outStream.skip(offset);
    for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
    byte[] outBuf = outStream.toByteArray();
    BitwiseInputStream inStream = new BitwiseInputStream(outBuf);
    byte[] inBufDup = new byte[inBuf.length];
    inStream.skip(offset);
    for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
    assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

BitwiseOutputStream (com.android.internal.util.BitwiseOutputStream)50 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 BitwiseInputStream (com.android.internal.util.BitwiseInputStream)42 Random (java.util.Random)13 CdmaSmsMessage (android.hardware.radio.V1_0.CdmaSmsMessage)5 FlakyTest (android.support.test.filters.FlakyTest)3 Test (org.junit.Test)3 CdmaSmsCbProgramData (android.telephony.cdma.CdmaSmsCbProgramData)2 SmsCbMessage (android.telephony.SmsCbMessage)1