}\r
\r
/**\r
- * <p>When QR Codes use multiple data blocks, they are actually interleave the bytes of each of them.\r
+ * <p>When QR Codes use multiple data blocks, they are actually interleaved.\r
* That is, the first byte of data block 1 to n is written, then the second bytes, and so on. This\r
* method will separate the data into original blocks.</p>\r
*\r
static DataBlock[] getDataBlocks(byte[] rawCodewords,\r
Version version,\r
ErrorCorrectionLevel ecLevel) {\r
+\r
+ if (rawCodewords.length != version.getTotalCodewords()) {\r
+ throw new IllegalArgumentException();\r
+ }\r
+\r
// Figure out the number and size of data blocks used by this version and\r
// error correction level\r
Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);\r
if (numCodewords == shorterBlocksTotalCodewords) {\r
break;\r
}\r
- if (numCodewords != shorterBlocksTotalCodewords + 1) {\r
- throw new IllegalArgumentException("Data block sizes differ by more than 1");\r
- }\r
longerBlocksStartAt--;\r
}\r
longerBlocksStartAt++;\r
result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];\r
}\r
}\r
-\r
- if (rawCodewordsOffset != rawCodewords.length) {\r
- throw new IllegalArgumentException();\r
- }\r
-\r
return result;\r
}\r
\r
// OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
mode = Mode.TERMINATOR;
} else {
- mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
+ try {
+ mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
+ } catch (IllegalArgumentException iae) {
+ throw ReaderException.getInstance();
+ }
}
if (!mode.equals(Mode.TERMINATOR)) {
if (mode.equals(Mode.FNC1_FIRST_POSITION) || mode.equals(Mode.FNC1_SECOND_POSITION)) {
fc1InEffect = true;
} else if (mode.equals(Mode.ECI)) {
// Count doesn't apply to ECI
- int value = parseECIValue(bits);
try {
+ int value = parseECIValue(bits);
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
} catch (IllegalArgumentException iae) {
- // unsupported... just continue?
+ throw ReaderException.getInstance();
}
} else {
// How many characters will follow, encoded in this mode?