X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Foned%2FUPCEReader.java;h=ef74b97050f3886541e66993c80a234e4b74188b;hb=ac343e4ddc7af1f54c2d2634abb1be992d183a35;hp=2b689778b6c4156822c2278e7f615337e100192f;hpb=b921215268ef412c6863e68e566bb7047ec1c4a4;p=zxing.git diff --git a/core/src/com/google/zxing/oned/UPCEReader.java b/core/src/com/google/zxing/oned/UPCEReader.java index 2b689778..ef74b970 100644 --- a/core/src/com/google/zxing/oned/UPCEReader.java +++ b/core/src/com/google/zxing/oned/UPCEReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 Google Inc. + * Copyright 2008 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,10 @@ package com.google.zxing.oned; -import com.google.zxing.ReaderException; import com.google.zxing.BarcodeFormat; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitArray; /** @@ -26,9 +28,9 @@ import com.google.zxing.common.BitArray; *

This is a great reference for * UPC-E information.

* - * @author srowen@google.com (Sean Owen) + * @author Sean Owen */ -public final class UPCEReader extends AbstractUPCEANReader { +public final class UPCEReader extends UPCEANReader { /** * The pattern that marks the middle, and end, of a UPC-E pattern. @@ -46,9 +48,19 @@ public final class UPCEReader extends AbstractUPCEANReader { {0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A} }; - protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result) throws ReaderException { + private final int[] decodeMiddleCounters; - int[] counters = new int[4]; + public UPCEReader() { + decodeMiddleCounters = new int[4]; + } + + protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result) + throws NotFoundException { + int[] counters = decodeMiddleCounters; + counters[0] = 0; + counters[1] = 0; + counters[2] = 0; + counters[3] = 0; int end = row.getSize(); int rowOffset = startRange[1]; @@ -70,16 +82,16 @@ public final class UPCEReader extends AbstractUPCEANReader { return rowOffset; } - protected int[] decodeEnd(BitArray row, int endStart) throws ReaderException { + protected int[] decodeEnd(BitArray row, int endStart) throws NotFoundException { return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN); } - protected boolean checkChecksum(String s) throws ReaderException { + protected boolean checkChecksum(String s) throws FormatException, ChecksumException { return super.checkChecksum(convertUPCEtoUPCA(s)); } private static void determineNumSysAndCheckDigit(StringBuffer resultString, int lgPatternFound) - throws ReaderException { + throws NotFoundException { for (int numSys = 0; numSys <= 1; numSys++) { for (int d = 0; d < 10; d++) { @@ -90,11 +102,11 @@ public final class UPCEReader extends AbstractUPCEANReader { } } } - throw new ReaderException("Unable to determine number system and check digit"); + throw NotFoundException.getNotFoundInstance(); } BarcodeFormat getBarcodeFormat() { - return BarcodeFormat.UPC_E; + return BarcodeFormat.UPC_E; } /** @@ -103,7 +115,7 @@ public final class UPCEReader extends AbstractUPCEANReader { * @param upce UPC-E code as string of digits * @return equivalent UPC-A code as string of digits */ - private static String convertUPCEtoUPCA(String upce) { + public static String convertUPCEtoUPCA(String upce) { char[] upceChars = new char[6]; upce.getChars(1, 7, upceChars, 0); StringBuffer result = new StringBuffer(12); @@ -138,4 +150,4 @@ public final class UPCEReader extends AbstractUPCEANReader { return result.toString(); } -} \ No newline at end of file +}