Esempio n. 1
0
 /**
  * Given data and error-correction codewords received, possibly corrupted by errors, attempts to
  * correct the errors in-place using Reed-Solomon error correction.
  *
  * @param codewordBytes data and error correction codewords
  * @param numDataCodewords number of codewords that are data bytes
  * @throws ChecksumException if error correction fails
  */
 private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {
   int numCodewords = codewordBytes.length;
   // First read into an array of ints
   int[] codewordsInts = new int[numCodewords];
   for (int i = 0; i < numCodewords; i++) {
     codewordsInts[i] = codewordBytes[i] & 0xFF;
   }
   try {
     rsDecoder.decode(codewordsInts, codewordBytes.length - numDataCodewords);
   } catch (ReedSolomonException ignored) {
     throw ChecksumException.getChecksumInstance();
   }
   // Copy back into array of bytes -- only need to worry about the bytes that were data
   // We don't care about errors in the error-correction codewords
   for (int i = 0; i < numDataCodewords; i++) {
     codewordBytes[i] = (byte) codewordsInts[i];
   }
 }
 private void checkQRRSDecode(int[] received) throws ReedSolomonException {
   qrRSDecoder.decode(received, QR_CODE_ECC_BYTES);
   for (int i = 0; i < QR_CODE_TEST.length; i++) {
     assertEquals(received[i], QR_CODE_TEST[i]);
   }
 }