diff --git a/core/src/com/google/zxing/common/BitSource.java b/core/src/com/google/zxing/common/BitSource.java index 10898fabe..e3f3246af 100755 --- a/core/src/com/google/zxing/common/BitSource.java +++ b/core/src/com/google/zxing/common/BitSource.java @@ -39,6 +39,13 @@ public final class BitSource { this.bytes = bytes; } + /** + * @return index of next bit in current byte which would be read by the next call to {@link #readBits(int)}. + */ + public int getBitOffset() { + return bitOffset; + } + /** * @return index of next byte in input byte array which would be read by the next call to {@link #readBits(int)}. */ diff --git a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java index a92fb29d7..8cc4f8849 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java @@ -413,7 +413,6 @@ final class DecodedBitStreamParser { * See ISO 16022:2006, 5.2.8 and Annex C Table C.3 */ private static void decodeEdifactSegment(BitSource bits, StringBuilder result) { - boolean unlatch = false; do { // If there is only two or less bytes left then it will be encoded as ASCII if (bits.available() <= 16) { @@ -425,19 +424,20 @@ final class DecodedBitStreamParser { // Check for the unlatch character if (edifactValue == 0x1F) { // 011111 - unlatch = true; - // If we encounter the unlatch code then continue reading because the Codeword triple - // is padded with 0's + // Read rest of byte, which should be 0, and stop + int bitsLeft = 8 - bits.getBitOffset(); + if (bitsLeft != 8) { + bits.readBits(bitsLeft); + } + return; } - if (!unlatch) { - if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit - edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value - } - result.append((char) edifactValue); + if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit + edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value } + result.append((char) edifactValue); } - } while (!unlatch && bits.available() > 0); + } while (bits.available() > 0); } /**