Merge change 5192 into donut
* changes: make BitwiseInputStream.read return int
This commit is contained in:
@@ -69,19 +69,19 @@ public class BitwiseInputStream {
|
||||
*
|
||||
* @return byte of read data (possibly partially filled, from lsb)
|
||||
*/
|
||||
public byte read(int bits) throws AccessException {
|
||||
public int read(int bits) throws AccessException {
|
||||
int index = mPos >>> 3;
|
||||
int offset = 16 - (mPos & 0x07) - bits; // &7==%8
|
||||
if ((bits < 0) || (bits > 8) || ((mPos + bits) > mEnd)) {
|
||||
throw new AccessException("illegal read " +
|
||||
"(pos " + mPos + ", end " + mEnd + ", bits " + bits + ")");
|
||||
}
|
||||
int data = (mBuf[index] & 0x00FF) << 8;
|
||||
if (offset < 8) data |= (mBuf[index + 1] & 0xFF);
|
||||
int data = (mBuf[index] & 0xFF) << 8;
|
||||
if (offset < 8) data |= mBuf[index + 1] & 0xFF;
|
||||
data >>>= offset;
|
||||
data &= (-1 >>> (32 - bits));
|
||||
mPos += bits;
|
||||
return (byte)data;
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,8 +95,8 @@ public class BitwiseOutputStream {
|
||||
int offset = 16 - (mPos & 0x07) - bits; // &7==%8
|
||||
data <<= offset;
|
||||
mPos += bits;
|
||||
mBuf[index] |= (data >>> 8);
|
||||
if (offset < 8) mBuf[index + 1] |= (data & 0x00FF);
|
||||
mBuf[index] |= data >>> 8;
|
||||
if (offset < 8) mBuf[index + 1] |= data & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -789,7 +789,7 @@ public final class BearerData {
|
||||
if (inStream.read(8) != 3) {
|
||||
throw new CodingException("MESSAGE_IDENTIFIER subparam size incorrect");
|
||||
}
|
||||
bData.messageType = inStream.read(4);
|
||||
bData.messageType = (byte)inStream.read(4);
|
||||
bData.messageId = inStream.read(8) << 8;
|
||||
bData.messageId |= inStream.read(8);
|
||||
bData.hasUserDataHeader = (inStream.read(1) == 1);
|
||||
@@ -799,7 +799,7 @@ public final class BearerData {
|
||||
private static void decodeUserData(BearerData bData, BitwiseInputStream inStream)
|
||||
throws BitwiseInputStream.AccessException
|
||||
{
|
||||
byte paramBytes = inStream.read(8);
|
||||
int paramBytes = inStream.read(8);
|
||||
bData.userData = new UserData();
|
||||
bData.userData.msgEncoding = inStream.read(5);
|
||||
bData.userData.msgEncodingSet = true;
|
||||
@@ -867,7 +867,7 @@ public final class BearerData {
|
||||
inStream.skip(offset);
|
||||
byte[] expandedData = new byte[numFields];
|
||||
for (int i = 0; i < numFields; i++) {
|
||||
expandedData[i] = inStream.read(7);
|
||||
expandedData[i] = (byte)inStream.read(7);
|
||||
}
|
||||
return new String(expandedData, 0, numFields, "US-ASCII");
|
||||
} catch (java.io.UnsupportedEncodingException ex) {
|
||||
@@ -922,7 +922,7 @@ public final class BearerData {
|
||||
private static void decodeReplyOption(BearerData bData, BitwiseInputStream inStream)
|
||||
throws BitwiseInputStream.AccessException, CodingException
|
||||
{
|
||||
byte paramBytes = inStream.read(8);
|
||||
int paramBytes = inStream.read(8);
|
||||
if (paramBytes != 1) {
|
||||
throw new CodingException("REPLY_OPTION subparam size incorrect");
|
||||
}
|
||||
@@ -985,18 +985,18 @@ public final class BearerData {
|
||||
private static void decodeCallbackNumber(BearerData bData, BitwiseInputStream inStream)
|
||||
throws BitwiseInputStream.AccessException, CodingException
|
||||
{
|
||||
byte paramBytes = inStream.read(8);
|
||||
int paramBytes = inStream.read(8);
|
||||
CdmaSmsAddress addr = new CdmaSmsAddress();
|
||||
addr.digitMode = inStream.read(1);
|
||||
addr.digitMode = (byte)inStream.read(1);
|
||||
byte fieldBits = 4;
|
||||
byte consumedBits = 1;
|
||||
if (addr.digitMode == CdmaSmsAddress.DIGIT_MODE_8BIT_CHAR) {
|
||||
addr.ton = inStream.read(3);
|
||||
addr.numberPlan = inStream.read(4);
|
||||
addr.numberPlan = (byte)inStream.read(4);
|
||||
fieldBits = 8;
|
||||
consumedBits += 7;
|
||||
}
|
||||
addr.numberOfDigits = inStream.read(8);
|
||||
addr.numberOfDigits = (byte)inStream.read(8);
|
||||
consumedBits += 8;
|
||||
int remainingBits = (paramBytes * 8) - consumedBits;
|
||||
int dataBits = addr.numberOfDigits * fieldBits;
|
||||
@@ -1076,7 +1076,7 @@ public final class BearerData {
|
||||
if (inStream.read(8) != 1) {
|
||||
throw new CodingException("PRIVACY_INDICATOR subparam size incorrect");
|
||||
}
|
||||
bData.privacy = inStream.read(2);
|
||||
bData.privacy = (byte)inStream.read(2);
|
||||
inStream.skip(6);
|
||||
bData.privacyIndicatorSet = true;
|
||||
}
|
||||
@@ -1097,7 +1097,7 @@ public final class BearerData {
|
||||
if (inStream.read(8) != 1) {
|
||||
throw new CodingException("DISPLAY_MODE subparam size incorrect");
|
||||
}
|
||||
bData.displayMode = inStream.read(2);
|
||||
bData.displayMode = (byte)inStream.read(2);
|
||||
inStream.skip(6);
|
||||
bData.displayModeSet = true;
|
||||
}
|
||||
@@ -1108,7 +1108,7 @@ public final class BearerData {
|
||||
if (inStream.read(8) != 1) {
|
||||
throw new CodingException("PRIORITY_INDICATOR subparam size incorrect");
|
||||
}
|
||||
bData.priority = inStream.read(2);
|
||||
bData.priority = (byte)inStream.read(2);
|
||||
inStream.skip(6);
|
||||
bData.priorityIndicatorSet = true;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BitwiseStreamsTest extends AndroidTestCase {
|
||||
private final static String LOG_TAG = "BitwiseStreamsTest";
|
||||
|
||||
@@ -39,7 +41,7 @@ public class BitwiseStreamsTest extends AndroidTestCase {
|
||||
BitwiseInputStream inStream = new BitwiseInputStream(outBuf);
|
||||
byte[] inBufDup = new byte[inBuf.length];
|
||||
inStream.skip(offset);
|
||||
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = inStream.read(8);
|
||||
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte)inStream.read(8);
|
||||
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ public class BitwiseStreamsTest extends AndroidTestCase {
|
||||
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] = inStream.read(8);
|
||||
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte)inStream.read(8);
|
||||
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
|
||||
}
|
||||
|
||||
@@ -67,7 +69,7 @@ public class BitwiseStreamsTest extends AndroidTestCase {
|
||||
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] = inStream.read(8);
|
||||
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte)inStream.read(8);
|
||||
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
|
||||
}
|
||||
|
||||
@@ -84,12 +86,33 @@ public class BitwiseStreamsTest extends AndroidTestCase {
|
||||
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] = inStream.read(8);
|
||||
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte)inStream.read(8);
|
||||
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testFive() throws Exception {
|
||||
Random random = new Random();
|
||||
int iterations = 10000;
|
||||
int[] sizeArr = new int[iterations];
|
||||
int[] valueArr = new int[iterations];
|
||||
BitwiseOutputStream outStream = new BitwiseOutputStream(iterations * 4);
|
||||
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]));
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testSix() throws Exception {
|
||||
int num_runs = 10;
|
||||
long start = android.os.SystemClock.elapsedRealtime();
|
||||
for (int run = 0; run < num_runs; run++) {
|
||||
@@ -104,7 +127,7 @@ public class BitwiseStreamsTest extends AndroidTestCase {
|
||||
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] = inStream.read(8);
|
||||
for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte)inStream.read(8);
|
||||
assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
|
||||
}
|
||||
long end = android.os.SystemClock.elapsedRealtime();
|
||||
|
||||
@@ -171,14 +171,14 @@ public class CdmaSmsTest extends AndroidTestCase {
|
||||
assertEquals(bearerData.msgCenterTimeStamp.minute, 1);
|
||||
assertEquals(bearerData.msgCenterTimeStamp.second, 59);
|
||||
assertEquals(bearerData.validityPeriodAbsolute, null);
|
||||
assertEquals(bearerData.validityPeriodRelative, -63);
|
||||
assertEquals(bearerData.validityPeriodRelative, 193);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.year, 1997);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.month, 5);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.monthDay, 18);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.hour, 0);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.minute, 0);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.second, 0);
|
||||
assertEquals(bearerData.deferredDeliveryTimeRelative, -57);
|
||||
assertEquals(bearerData.deferredDeliveryTimeRelative, 199);
|
||||
assertEquals(bearerData.hasUserDataHeader, false);
|
||||
assertEquals(bearerData.userData.msgEncoding, UserData.ENCODING_7BIT_ASCII);
|
||||
assertEquals(bearerData.userData.numFields, 2);
|
||||
@@ -225,7 +225,7 @@ public class CdmaSmsTest extends AndroidTestCase {
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.hour, 0);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.minute, 0);
|
||||
assertEquals(bearerData.deferredDeliveryTimeAbsolute.second, 0);
|
||||
assertEquals(bearerData.deferredDeliveryTimeRelative, -110);
|
||||
assertEquals(bearerData.deferredDeliveryTimeRelative, 146);
|
||||
assertEquals(bearerData.hasUserDataHeader, false);
|
||||
assertEquals(bearerData.userData.msgEncoding, UserData.ENCODING_7BIT_ASCII);
|
||||
assertEquals(bearerData.userData.numFields, 2);
|
||||
|
||||
Reference in New Issue
Block a user