Update deps including Guava 20; use switch in pref to chained if-else for slightly more consistent style

This commit is contained in:
Sean Owen 2016-11-11 20:20:46 +00:00
parent 995da03a39
commit 28f8bd37f3
No known key found for this signature in database
GPG key ID: F6CE9695C9318406
11 changed files with 422 additions and 327 deletions

View file

@ -82,10 +82,13 @@ public final class WifiConfigManager extends AsyncTask<WifiParsedResult,Object,O
} else {
String password = theWifiResult.getPassword();
if (password != null && !password.isEmpty()) {
if (networkType == NetworkType.WEP) {
changeNetworkWEP(wifiManager, theWifiResult);
} else if (networkType == NetworkType.WPA) {
changeNetworkWPA(wifiManager, theWifiResult);
switch (networkType) {
case WEP:
changeNetworkWEP(wifiManager, theWifiResult);
break;
case WPA:
changeNetworkWPA(wifiManager, theWifiResult);
break;
}
}
}

View file

@ -146,39 +146,49 @@ final class DecodedBitStreamParser {
result.append('0');
}
result.append(value);
} else if (oneByte == 230) { // Latch to C40 encodation
return Mode.C40_ENCODE;
} else if (oneByte == 231) { // Latch to Base 256 encodation
return Mode.BASE256_ENCODE;
} else if (oneByte == 232) {
// FNC1
result.append((char) 29); // translate as ASCII 29
} else if (oneByte == 233 || oneByte == 234) {
// Structured Append, Reader Programming
// Ignore these symbols for now
//throw ReaderException.getInstance();
} else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII)
upperShift = true;
} else if (oneByte == 236) { // 05 Macro
result.append("[)>\u001E05\u001D");
resultTrailer.insert(0, "\u001E\u0004");
} else if (oneByte == 237) { // 06 Macro
result.append("[)>\u001E06\u001D");
resultTrailer.insert(0, "\u001E\u0004");
} else if (oneByte == 238) { // Latch to ANSI X12 encodation
return Mode.ANSIX12_ENCODE;
} else if (oneByte == 239) { // Latch to Text encodation
return Mode.TEXT_ENCODE;
} else if (oneByte == 240) { // Latch to EDIFACT encodation
return Mode.EDIFACT_ENCODE;
} else if (oneByte == 241) { // ECI Character
// TODO(bbrown): I think we need to support ECI
//throw ReaderException.getInstance();
// Ignore this symbol for now
} else if (oneByte >= 242) { // Not to be used in ASCII encodation
// ... but work around encoders that end with 254, latch back to ASCII
if (oneByte != 254 || bits.available() != 0) {
throw FormatException.getFormatInstance();
} else {
switch (oneByte) {
case 230: // Latch to C40 encodation
return Mode.C40_ENCODE;
case 231: // Latch to Base 256 encodation
return Mode.BASE256_ENCODE;
case 232: // FNC1
result.append((char) 29); // translate as ASCII 29
break;
case 233: // Structured Append
case 234: // Reader Programming
// Ignore these symbols for now
//throw ReaderException.getInstance();
break;
case 235: // Upper Shift (shift to Extended ASCII)
upperShift = true;
break;
case 236: // 05 Macro
result.append("[)>\u001E05\u001D");
resultTrailer.insert(0, "\u001E\u0004");
break;
case 237: // 06 Macro
result.append("[)>\u001E06\u001D");
resultTrailer.insert(0, "\u001E\u0004");
break;
case 238: // Latch to ANSI X12 encodation
return Mode.ANSIX12_ENCODE;
case 239: // Latch to Text encodation
return Mode.TEXT_ENCODE;
case 240: // Latch to EDIFACT encodation
return Mode.EDIFACT_ENCODE;
case 241: // ECI Character
// TODO(bbrown): I think we need to support ECI
//throw ReaderException.getInstance();
// Ignore this symbol for now
break;
default:
// Not to be used in ASCII encodation
// but work around encoders that end with 254, latch back to ASCII
if (oneByte >= 242 && (oneByte != 254 || bits.available() != 0)) {
throw FormatException.getFormatInstance();
}
break;
}
}
} while (bits.available() > 0);
@ -245,12 +255,17 @@ final class DecodedBitStreamParser {
} else {
result.append(c40char);
}
} else if (cValue == 27) { // FNC1
result.append((char) 29); // translate as ASCII 29
} else if (cValue == 30) { // Upper Shift
upperShift = true;
} else {
throw FormatException.getFormatInstance();
switch (cValue) {
case 27: // FNC1
result.append((char) 29); // translate as ASCII 29
break;
case 30: // Upper Shift
upperShift = true;
break;
default:
throw FormatException.getFormatInstance();
}
}
shift = 0;
break;
@ -330,12 +345,17 @@ final class DecodedBitStreamParser {
} else {
result.append(textChar);
}
} else if (cValue == 27) { // FNC1
result.append((char) 29); // translate as ASCII 29
} else if (cValue == 30) { // Upper Shift
upperShift = true;
} else {
throw FormatException.getFormatInstance();
switch (cValue) {
case 27: // FNC1
result.append((char) 29); // translate as ASCII 29
break;
case 30: // Upper Shift
upperShift = true;
break;
default:
throw FormatException.getFormatInstance();
}
}
shift = 0;
break;
@ -383,20 +403,28 @@ final class DecodedBitStreamParser {
for (int i = 0; i < 3; i++) {
int cValue = cValues[i];
if (cValue == 0) { // X12 segment terminator <CR>
result.append('\r');
} else if (cValue == 1) { // X12 segment separator *
result.append('*');
} else if (cValue == 2) { // X12 sub-element separator >
result.append('>');
} else if (cValue == 3) { // space
result.append(' ');
} else if (cValue < 14) { // 0 - 9
result.append((char) (cValue + 44));
} else if (cValue < 40) { // A - Z
result.append((char) (cValue + 51));
} else {
throw FormatException.getFormatInstance();
switch (cValue) {
case 0: // X12 segment terminator <CR>
result.append('\r');
break;
case 1: // X12 segment separator *
result.append('*');
break;
case 2: // X12 sub-element separator >
result.append('>');
break;
case 3: // space
result.append(' ');
break;
default:
if (cValue < 14) { // 0 - 9
result.append((char) (cValue + 44));
} else if (cValue < 40) { // A - Z
result.append((char) (cValue + 51));
} else {
throw FormatException.getFormatInstance();
}
break;
}
}
} while (bits.available() > 0);

View file

@ -49,20 +49,28 @@ final class X12Encoder extends C40Encoder {
@Override
int encodeChar(char c, StringBuilder sb) {
if (c == '\r') {
sb.append('\0');
} else if (c == '*') {
sb.append('\1');
} else if (c == '>') {
sb.append('\2');
} else if (c == ' ') {
sb.append('\3');
} else if (c >= '0' && c <= '9') {
sb.append((char) (c - 48 + 4));
} else if (c >= 'A' && c <= 'Z') {
sb.append((char) (c - 65 + 14));
} else {
HighLevelEncoder.illegalCharacter(c);
switch (c) {
case '\r':
sb.append('\0');
break;
case '*':
sb.append('\1');
break;
case '>':
sb.append('\2');
break;
case ' ':
sb.append('\3');
break;
default:
if (c >= '0' && c <= '9') {
sb.append((char) (c - 48 + 4));
} else if (c >= 'A' && c <= 'Z') {
sb.append((char) (c - 65 + 14));
} else {
HighLevelEncoder.illegalCharacter(c);
}
break;
}
return 1;
}

View file

@ -212,16 +212,16 @@ public final class Code128Writer extends OneDimensionalCodeWriter {
return CODE_CODE_B; // no choice
}
if (oldCode == CODE_CODE_C) { // can continue in code C
return oldCode;
return CODE_CODE_C;
}
if (oldCode == CODE_CODE_B) {
if (lookahead == CType.FNC_1) {
return oldCode; // can continue in code B
return CODE_CODE_B; // can continue in code B
}
// Seen two consecutive digits, see what follows
lookahead = findCType(value, start + 2);
if (lookahead == CType.UNCODABLE || lookahead == CType.ONE_DIGIT) {
return oldCode; // not worth switching now
return CODE_CODE_B; // not worth switching now
}
if (lookahead == CType.FNC_1) { // two digits, then FNC_1...
lookahead = findCType(value, start + 3);

View file

@ -173,33 +173,35 @@ final class DecodedBitStreamParser {
codeIndex = textCompaction(codewords, codeIndex, fileId);
resultMetadata.setFileId(fileId.toString());
if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
codeIndex++;
int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
int additionalOptionCodeWordsIndex = 0;
switch (codewords[codeIndex]) {
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
codeIndex++;
int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
int additionalOptionCodeWordsIndex = 0;
boolean end = false;
while ((codeIndex < codewords[0]) && !end) {
int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) {
additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
} else {
switch (code) {
case MACRO_PDF417_TERMINATOR:
resultMetadata.setLastSegment(true);
codeIndex++;
end = true;
break;
default:
throw FormatException.getFormatInstance();
boolean end = false;
while ((codeIndex < codewords[0]) && !end) {
int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) {
additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
} else {
switch (code) {
case MACRO_PDF417_TERMINATOR:
resultMetadata.setLastSegment(true);
codeIndex++;
end = true;
break;
default:
throw FormatException.getFormatInstance();
}
}
}
}
resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
} else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
resultMetadata.setLastSegment(true);
codeIndex++;
resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
break;
case MACRO_PDF417_TERMINATOR:
resultMetadata.setLastSegment(true);
codeIndex++;
break;
}
return codeIndex;
@ -300,20 +302,27 @@ final class DecodedBitStreamParser {
// Upper case Alpha Character
ch = (char) ('A' + subModeCh);
} else {
if (subModeCh == 26) {
ch = ' ';
} else if (subModeCh == LL) {
subMode = Mode.LOWER;
} else if (subModeCh == ML) {
subMode = Mode.MIXED;
} else if (subModeCh == PS) {
// Shift to punctuation
priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
switch (subModeCh) {
case 26:
ch = ' ';
break;
case LL:
subMode = Mode.LOWER;
break;
case ML:
subMode = Mode.MIXED;
break;
case PS:
// Shift to punctuation
priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -323,23 +332,30 @@ final class DecodedBitStreamParser {
if (subModeCh < 26) {
ch = (char) ('a' + subModeCh);
} else {
if (subModeCh == 26) {
ch = ' ';
} else if (subModeCh == AS) {
// Shift to alpha
priorToShiftMode = subMode;
subMode = Mode.ALPHA_SHIFT;
} else if (subModeCh == ML) {
subMode = Mode.MIXED;
} else if (subModeCh == PS) {
// Shift to punctuation
priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
// TODO Does this need to use the current character encoding? See other occurrences below
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
switch (subModeCh) {
case 26:
ch = ' ';
break;
case AS:
// Shift to alpha
priorToShiftMode = subMode;
subMode = Mode.ALPHA_SHIFT;
break;
case ML:
subMode = Mode.MIXED;
break;
case PS:
// Shift to punctuation
priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
// TODO Does this need to use the current character encoding? See other occurrences below
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -349,22 +365,30 @@ final class DecodedBitStreamParser {
if (subModeCh < PL) {
ch = MIXED_CHARS[subModeCh];
} else {
if (subModeCh == PL) {
subMode = Mode.PUNCT;
} else if (subModeCh == 26) {
ch = ' ';
} else if (subModeCh == LL) {
subMode = Mode.LOWER;
} else if (subModeCh == AL) {
subMode = Mode.ALPHA;
} else if (subModeCh == PS) {
// Shift to punctuation
priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
switch (subModeCh) {
case PL:
subMode = Mode.PUNCT;
break;
case 26:
ch = ' ';
break;
case LL:
subMode = Mode.LOWER;
break;
case AL:
subMode = Mode.ALPHA;
break;
case PS:
// Shift to punctuation
priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -374,12 +398,16 @@ final class DecodedBitStreamParser {
if (subModeCh < PAL) {
ch = PUNCT_CHARS[subModeCh];
} else {
if (subModeCh == PAL) {
subMode = Mode.ALPHA;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
switch (subModeCh) {
case PAL:
subMode = Mode.ALPHA;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -390,10 +418,13 @@ final class DecodedBitStreamParser {
if (subModeCh < 26) {
ch = (char) ('A' + subModeCh);
} else {
if (subModeCh == 26) {
ch = ' ';
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
switch (subModeCh) {
case 26:
ch = ' ';
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -404,14 +435,18 @@ final class DecodedBitStreamParser {
if (subModeCh < PAL) {
ch = PUNCT_CHARS[subModeCh];
} else {
if (subModeCh == PAL) {
subMode = Mode.ALPHA;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
// PS before Shift-to-Byte is used as a padding character,
// see 5.4.2.4 of the specification
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
switch (subModeCh) {
case PAL:
subMode = Mode.ALPHA;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
// PS before Shift-to-Byte is used as a padding character,
// see 5.4.2.4 of the specification
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -442,30 +477,85 @@ final class DecodedBitStreamParser {
int codeIndex,
StringBuilder result) {
ByteArrayOutputStream decodedBytes = new ByteArrayOutputStream();
if (mode == BYTE_COMPACTION_MODE_LATCH) {
// Total number of Byte Compaction characters to be encoded
// is not a multiple of 6
int count = 0;
long value = 0;
int[] byteCompactedCodewords = new int[6];
boolean end = false;
int nextCode = codewords[codeIndex++];
while ((codeIndex < codewords[0]) && !end) {
byteCompactedCodewords[count++] = nextCode;
// Base 900
value = 900 * value + nextCode;
nextCode = codewords[codeIndex++];
// perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH
if (nextCode == TEXT_COMPACTION_MODE_LATCH ||
nextCode == BYTE_COMPACTION_MODE_LATCH ||
nextCode == NUMERIC_COMPACTION_MODE_LATCH ||
nextCode == BYTE_COMPACTION_MODE_LATCH_6 ||
nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||
nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||
nextCode == MACRO_PDF417_TERMINATOR) {
codeIndex--;
end = true;
} else {
int count = 0;
long value = 0;
boolean end = false;
switch (mode) {
case BYTE_COMPACTION_MODE_LATCH:
// Total number of Byte Compaction characters to be encoded
// is not a multiple of 6
int[] byteCompactedCodewords = new int[6];
int nextCode = codewords[codeIndex++];
while ((codeIndex < codewords[0]) && !end) {
byteCompactedCodewords[count++] = nextCode;
// Base 900
value = 900 * value + nextCode;
nextCode = codewords[codeIndex++];
// perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH
switch (nextCode) {
case TEXT_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH:
case NUMERIC_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH_6:
case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
case MACRO_PDF417_TERMINATOR:
codeIndex--;
end = true;
break;
default:
if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords
// Convert to Base 256
for (int j = 0; j < 6; ++j) {
decodedBytes.write((byte) (value >> (8 * (5 - j))));
}
value = 0;
count = 0;
}
break;
}
}
// if the end of all codewords is reached the last codeword needs to be added
if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) {
byteCompactedCodewords[count++] = nextCode;
}
// If Byte Compaction mode is invoked with codeword 901,
// the last group of codewords is interpreted directly
// as one byte per codeword, without compaction.
for (int i = 0; i < count; i++) {
decodedBytes.write((byte) byteCompactedCodewords[i]);
}
break;
case BYTE_COMPACTION_MODE_LATCH_6:
// Total number of Byte Compaction characters to be encoded
// is an integer multiple of 6
while (codeIndex < codewords[0] && !end) {
int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) {
count++;
// Base 900
value = 900 * value + code;
} else {
switch (code) {
case TEXT_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH:
case NUMERIC_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH_6:
case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
case MACRO_PDF417_TERMINATOR:
codeIndex--;
end = true;
break;
}
}
if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords
// Convert to Base 256
@ -476,54 +566,7 @@ final class DecodedBitStreamParser {
count = 0;
}
}
}
// if the end of all codewords is reached the last codeword needs to be added
if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) {
byteCompactedCodewords[count++] = nextCode;
}
// If Byte Compaction mode is invoked with codeword 901,
// the last group of codewords is interpreted directly
// as one byte per codeword, without compaction.
for (int i = 0; i < count; i++) {
decodedBytes.write((byte) byteCompactedCodewords[i]);
}
} else if (mode == BYTE_COMPACTION_MODE_LATCH_6) {
// Total number of Byte Compaction characters to be encoded
// is an integer multiple of 6
int count = 0;
long value = 0;
boolean end = false;
while (codeIndex < codewords[0] && !end) {
int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) {
count++;
// Base 900
value = 900 * value + code;
} else {
if (code == TEXT_COMPACTION_MODE_LATCH ||
code == BYTE_COMPACTION_MODE_LATCH ||
code == NUMERIC_COMPACTION_MODE_LATCH ||
code == BYTE_COMPACTION_MODE_LATCH_6 ||
code == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||
code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||
code == MACRO_PDF417_TERMINATOR) {
codeIndex--;
end = true;
}
}
if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords
// Convert to Base 256
for (int j = 0; j < 6; ++j) {
decodedBytes.write((byte) (value >> (8 * (5 - j))));
}
value = 0;
count = 0;
}
}
break;
}
result.append(new String(decodedBytes.toByteArray(), encoding));
return codeIndex;
@ -552,14 +595,16 @@ final class DecodedBitStreamParser {
numericCodewords[count] = code;
count++;
} else {
if (code == TEXT_COMPACTION_MODE_LATCH ||
code == BYTE_COMPACTION_MODE_LATCH ||
code == BYTE_COMPACTION_MODE_LATCH_6 ||
code == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||
code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||
code == MACRO_PDF417_TERMINATOR) {
codeIndex--;
end = true;
switch (code) {
case TEXT_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH_6:
case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
case MACRO_PDF417_TERMINATOR:
codeIndex--;
end = true;
break;
}
}
if (count % MAX_NUMERIC_CODEWORDS == 0 ||

View file

@ -269,8 +269,7 @@ public final class Detector {
int x = patternStart;
int counterPosition = 0;
int patternLength = pattern.length;
boolean isWhite = whiteFirst;
for (; x < width; x++) {
for (boolean isWhite = whiteFirst; x < width; x++) {
boolean pixel = matrix.get(x, row);
if (pixel ^ isWhite) {
counters[counterPosition]++;

View file

@ -179,56 +179,58 @@ final class PDF417HighLevelEncoder {
int textSubMode = SUBMODE_ALPHA;
// User selected encoding mode
if (compaction == Compaction.TEXT) {
encodeText(msg, p, len, sb, textSubMode);
} else if (compaction == Compaction.BYTE) {
byte[] bytes = msg.getBytes(encoding);
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb);
} else if (compaction == Compaction.NUMERIC) {
sb.append((char) LATCH_TO_NUMERIC);
encodeNumeric(msg, p, len, sb);
} else {
int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
while (p < len) {
int n = determineConsecutiveDigitCount(msg, p);
if (n >= 13) {
sb.append((char) LATCH_TO_NUMERIC);
encodingMode = NUMERIC_COMPACTION;
textSubMode = SUBMODE_ALPHA; //Reset after latch
encodeNumeric(msg, p, n, sb);
p += n;
} else {
int t = determineConsecutiveTextCount(msg, p);
if (t >= 5 || n == len) {
if (encodingMode != TEXT_COMPACTION) {
sb.append((char) LATCH_TO_TEXT);
encodingMode = TEXT_COMPACTION;
textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
}
textSubMode = encodeText(msg, p, t, sb, textSubMode);
p += t;
switch (compaction) {
case TEXT:
encodeText(msg, p, len, sb, textSubMode);
break;
case BYTE:
byte[] msgBytes = msg.getBytes(encoding);
encodeBinary(msgBytes, p, msgBytes.length, BYTE_COMPACTION, sb);
break;
case NUMERIC:
sb.append((char) LATCH_TO_NUMERIC);
encodeNumeric(msg, p, len, sb);
break;
default:
int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
while (p < len) {
int n = determineConsecutiveDigitCount(msg, p);
if (n >= 13) {
sb.append((char) LATCH_TO_NUMERIC);
encodingMode = NUMERIC_COMPACTION;
textSubMode = SUBMODE_ALPHA; //Reset after latch
encodeNumeric(msg, p, n, sb);
p += n;
} else {
int b = determineConsecutiveBinaryCount(msg, p, encoding);
if (b == 0) {
b = 1;
}
byte[] bytes = msg.substring(p, p + b).getBytes(encoding);
if (bytes.length == 1 && encodingMode == TEXT_COMPACTION) {
//Switch for one byte (instead of latch)
encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb);
int t = determineConsecutiveTextCount(msg, p);
if (t >= 5 || n == len) {
if (encodingMode != TEXT_COMPACTION) {
sb.append((char) LATCH_TO_TEXT);
encodingMode = TEXT_COMPACTION;
textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
}
textSubMode = encodeText(msg, p, t, sb, textSubMode);
p += t;
} else {
//Mode latch performed by encodeBinary()
encodeBinary(bytes, 0, bytes.length, encodingMode, sb);
encodingMode = BYTE_COMPACTION;
textSubMode = SUBMODE_ALPHA; //Reset after latch
int b = determineConsecutiveBinaryCount(msg, p, encoding);
if (b == 0) {
b = 1;
}
byte[] bytes = msg.substring(p, p + b).getBytes(encoding);
if (bytes.length == 1 && encodingMode == TEXT_COMPACTION) {
//Switch for one byte (instead of latch)
encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb);
} else {
//Mode latch performed by encodeBinary()
encodeBinary(bytes, 0, bytes.length, encodingMode, sb);
encodingMode = BYTE_COMPACTION;
textSubMode = SUBMODE_ALPHA; //Reset after latch
}
p += b;
}
p += b;
}
}
}
break;
}
return sb.toString();

View file

@ -71,11 +71,15 @@ final class DecodedBitStreamParser {
} else {
mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
}
if (mode != Mode.TERMINATOR) {
if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
switch (mode) {
case TERMINATOR:
break;
case FNC1_FIRST_POSITION:
case FNC1_SECOND_POSITION:
// We do little with FNC1 except alter the parsed result a bit according to the spec
fc1InEffect = true;
} else if (mode == Mode.STRUCTURED_APPEND) {
break;
case STRUCTURED_APPEND:
if (bits.available() < 16) {
throw FormatException.getFormatInstance();
}
@ -83,39 +87,45 @@ final class DecodedBitStreamParser {
// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
symbolSequence = bits.readBits(8);
parityData = bits.readBits(8);
} else if (mode == Mode.ECI) {
break;
case ECI:
// Count doesn't apply to ECI
int value = parseECIValue(bits);
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
if (currentCharacterSetECI == null) {
throw FormatException.getFormatInstance();
}
} else {
break;
case HANZI:
// First handle Hanzi mode which does not start with character count
if (mode == Mode.HANZI) {
//chinese mode contains a sub set indicator right after mode indicator
int subset = bits.readBits(4);
int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
if (subset == GB2312_SUBSET) {
decodeHanziSegment(bits, result, countHanzi);
}
} else {
// "Normal" QR code modes:
// How many characters will follow, encoded in this mode?
int count = bits.readBits(mode.getCharacterCountBits(version));
if (mode == Mode.NUMERIC) {
decodeNumericSegment(bits, result, count);
} else if (mode == Mode.ALPHANUMERIC) {
decodeAlphanumericSegment(bits, result, count, fc1InEffect);
} else if (mode == Mode.BYTE) {
decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
} else if (mode == Mode.KANJI) {
decodeKanjiSegment(bits, result, count);
} else {
throw FormatException.getFormatInstance();
}
// Chinese mode contains a sub set indicator right after mode indicator
int subset = bits.readBits(4);
int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
if (subset == GB2312_SUBSET) {
decodeHanziSegment(bits, result, countHanzi);
}
}
break;
default:
// "Normal" QR code modes:
// How many characters will follow, encoded in this mode?
int count = bits.readBits(mode.getCharacterCountBits(version));
switch (mode) {
case NUMERIC:
decodeNumericSegment(bits, result, count);
break;
case ALPHANUMERIC:
decodeAlphanumericSegment(bits, result, count, fc1InEffect);
break;
case BYTE:
decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
break;
case KANJI:
decodeKanjiSegment(bits, result, count);
break;
default:
throw FormatException.getFormatInstance();
}
break;
}
} while (mode != Mode.TERMINATOR);
} catch (IllegalArgumentException iae) {

View file

@ -44,7 +44,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
@ -95,7 +95,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
<maven.version.min>3.2.1</maven.version.min>
<proguard.version>5.2.1</proguard.version>
<proguard.version>5.3.1</proguard.version>
<proguard.plugin.version>2.0.13</proguard.plugin.version>
<slf4j.version>1.7.21</slf4j.version>
<!-- This can't reference project.version as some subprojects version differently -->
@ -170,7 +170,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.6.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>

View file

@ -37,7 +37,7 @@
</parent>
<properties>
<gwt.version>2.8.0-rc2</gwt.version>
<gwt.version>2.8.0</gwt.version>
</properties>
<build>

View file

@ -57,7 +57,7 @@
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.0.RC0</version>
<version>9.4.0.RC1</version>
</plugin>
</plugins>
</build>