From ac343e4ddc7af1f54c2d2634abb1be992d183a35 Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 2 Feb 2010 08:23:46 +0000 Subject: [PATCH] "Split" ReaderException into subclasses to enable more useful error reporting git-svn-id: http://zxing.googlecode.com/svn/trunk@1195 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- core/src/com/google/zxing/Binarizer.java | 4 +- core/src/com/google/zxing/BinaryBitmap.java | 4 +- .../com/google/zxing/ChecksumException.java | 37 ++++++++++++++ .../src/com/google/zxing/FormatException.java | 38 ++++++++++++++ .../com/google/zxing/MultiFormatReader.java | 18 +++---- .../com/google/zxing/NotFoundException.java | 37 ++++++++++++++ core/src/com/google/zxing/Reader.java | 8 +-- .../src/com/google/zxing/ReaderException.java | 14 +++--- .../zxing/common/DefaultGridSampler.java | 8 +-- .../common/GlobalHistogramBinarizer.java | 10 ++-- .../com/google/zxing/common/GridSampler.java | 16 +++--- .../google/zxing/common/HybridBinarizer.java | 6 +-- .../detector/MonochromeRectangleDetector.java | 14 +++--- .../zxing/datamatrix/DataMatrixReader.java | 28 ++++++----- .../datamatrix/decoder/BitMatrixParser.java | 18 +++---- .../decoder/DecodedBitStreamParser.java | 34 ++++++------- .../zxing/datamatrix/decoder/Decoder.java | 19 ++++--- .../zxing/datamatrix/decoder/Version.java | 10 ++-- .../zxing/datamatrix/detector/Detector.java | 10 ++-- .../google/zxing/multi/ByQuadrantReader.java | 18 ++++--- .../multi/GenericMultipleBarcodeReader.java | 11 ++-- .../zxing/multi/MultipleBarcodeReader.java | 8 +-- .../zxing/multi/qrcode/QRCodeMultiReader.java | 5 +- .../multi/qrcode/detector/MultiDetector.java | 11 ++-- .../detector/MultiFinderPatternFinder.java | 14 +++--- .../com/google/zxing/oned/Code128Reader.java | 25 ++++++---- .../com/google/zxing/oned/Code39Reader.java | 33 ++++++------ .../com/google/zxing/oned/EAN13Reader.java | 10 ++-- .../src/com/google/zxing/oned/EAN8Reader.java | 4 +- core/src/com/google/zxing/oned/ITFReader.java | 43 ++++++++-------- .../zxing/oned/MultiFormatOneDReader.java | 6 +-- .../zxing/oned/MultiFormatUPCEANReader.java | 5 +- .../src/com/google/zxing/oned/OneDReader.java | 35 +++++++------ .../src/com/google/zxing/oned/UPCAReader.java | 21 ++++---- .../com/google/zxing/oned/UPCEANReader.java | 50 ++++++++++--------- .../src/com/google/zxing/oned/UPCEReader.java | 14 +++--- .../com/google/zxing/pdf417/PDF417Reader.java | 22 ++++---- .../zxing/pdf417/decoder/BitMatrixParser.java | 4 +- .../decoder/DecodedBitStreamParser.java | 6 +-- .../google/zxing/pdf417/decoder/Decoder.java | 33 ++++++------ .../zxing/pdf417/detector/Detector.java | 46 ++++++++--------- .../com/google/zxing/qrcode/QRCodeReader.java | 28 ++++++----- .../com/google/zxing/qrcode/QRCodeWriter.java | 2 +- .../zxing/qrcode/decoder/BitMatrixParser.java | 26 +++++----- .../decoder/DecodedBitStreamParser.java | 28 +++++------ .../google/zxing/qrcode/decoder/Decoder.java | 29 +++++++---- .../google/zxing/qrcode/decoder/Version.java | 10 ++-- .../detector/AlignmentPatternFinder.java | 8 +-- .../zxing/qrcode/detector/Detector.java | 33 ++++++------ .../qrcode/detector/FinderPatternFinder.java | 12 ++--- .../google/zxing/qrcode/encoder/Encoder.java | 6 +-- .../AddressBookParsedResultTestCase.java | 4 +- .../result/CalendarParsedResultTestCase.java | 4 +- .../EmailAddressParsedResultTestCase.java | 4 +- .../result/GeoParsedResultTestCase.java | 4 +- .../result/ISBNParsedResultTestCase.java | 4 +- .../result/ProductParsedResultTestCase.java | 4 +- .../result/SMSMMSParsedResultTestCase.java | 4 +- .../result/TelParsedResultTestCase.java | 4 +- .../result/URIParsedResultTestCase.java | 4 +- .../common/AbstractBlackBoxTestCase.java | 4 +- .../AbstractNegativeBlackBoxTestCase.java | 3 +- .../DecodedBitStreamParserTestCase.java | 6 +-- .../zxing/oned/Code39BlackBox1TestCase.java | 2 +- .../zxing/oned/Code39BlackBox3TestCase.java | 2 +- .../oned/Code39ExtendedBlackBox2TestCase.java | 2 +- .../zxing/oned/EAN13BlackBox1TestCase.java | 2 +- .../zxing/oned/EAN13BlackBox2TestCase.java | 2 +- .../zxing/oned/EAN13BlackBox3TestCase.java | 4 +- .../zxing/oned/EAN8BlackBox1TestCase.java | 2 +- .../zxing/oned/UPCABlackBox1TestCase.java | 2 +- .../zxing/oned/UPCABlackBox2TestCase.java | 2 +- .../oned/UPCABlackBox3ReflectiveTestCase.java | 2 +- .../zxing/oned/UPCABlackBox4TestCase.java | 2 +- .../zxing/oned/UPCEBlackBox1TestCase.java | 2 +- .../zxing/oned/UPCEBlackBox2TestCase.java | 2 +- .../oned/UPCEBlackBox3ReflectiveTestCase.java | 2 +- .../zxing/qrcode/QRCodeBlackBox1TestCase.java | 2 +- .../zxing/qrcode/QRCodeBlackBox2TestCase.java | 2 +- .../zxing/qrcode/QRCodeBlackBox3TestCase.java | 2 +- .../zxing/qrcode/QRCodeBlackBox4TestCase.java | 2 +- .../zxing/qrcode/QRCodeBlackBox5TestCase.java | 2 +- .../DecodedBitStreamParserTestCase.java | 7 ++- .../zxing/qrcode/decoder/VersionTestCase.java | 3 +- .../zxing/client/j2se/CommandLineRunner.java | 9 ++-- .../zxing/client/j2se/ImageConverter.java | 5 +- .../com/google/zxing/web/DecodeServlet.java | 17 +++++-- zxingorg/web/format.jspx | 36 +++++++++++++ 88 files changed, 657 insertions(+), 448 deletions(-) create mode 100644 core/src/com/google/zxing/ChecksumException.java create mode 100644 core/src/com/google/zxing/FormatException.java create mode 100644 core/src/com/google/zxing/NotFoundException.java create mode 100644 zxingorg/web/format.jspx diff --git a/core/src/com/google/zxing/Binarizer.java b/core/src/com/google/zxing/Binarizer.java index 4fd83b57..912a3b55 100644 --- a/core/src/com/google/zxing/Binarizer.java +++ b/core/src/com/google/zxing/Binarizer.java @@ -55,7 +55,7 @@ public abstract class Binarizer { * If used, the Binarizer will call BitArray.clear(). Always use the returned object. * @return The array of bits for this row (true means black). */ - public abstract BitArray getBlackRow(int y, BitArray row) throws ReaderException; + public abstract BitArray getBlackRow(int y, BitArray row) throws NotFoundException; /** * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive @@ -65,7 +65,7 @@ public abstract class Binarizer { * * @return The 2D array of bits for the image (true means black). */ - public abstract BitMatrix getBlackMatrix() throws ReaderException; + public abstract BitMatrix getBlackMatrix() throws NotFoundException; /** * Creates a new object with the same type as this Binarizer implementation, but with pristine diff --git a/core/src/com/google/zxing/BinaryBitmap.java b/core/src/com/google/zxing/BinaryBitmap.java index 377a54b5..b97e4670 100644 --- a/core/src/com/google/zxing/BinaryBitmap.java +++ b/core/src/com/google/zxing/BinaryBitmap.java @@ -62,7 +62,7 @@ public final class BinaryBitmap { * If used, the Binarizer will call BitArray.clear(). Always use the returned object. * @return The array of bits for this row (true means black). */ - public BitArray getBlackRow(int y, BitArray row) throws ReaderException { + public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { return binarizer.getBlackRow(y, row); } @@ -74,7 +74,7 @@ public final class BinaryBitmap { * * @return The 2D array of bits for the image (true means black). */ - public BitMatrix getBlackMatrix() throws ReaderException { + public BitMatrix getBlackMatrix() throws NotFoundException { // The matrix is created on demand the first time it is requested, then cached. There are two // reasons for this: // 1. This work will never be done if the caller only installs 1D Reader objects, or if a diff --git a/core/src/com/google/zxing/ChecksumException.java b/core/src/com/google/zxing/ChecksumException.java new file mode 100644 index 00000000..dedb4be9 --- /dev/null +++ b/core/src/com/google/zxing/ChecksumException.java @@ -0,0 +1,37 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing; + +/** + * Thrown when a barcode was successfully detected and decoded, but + * was not returned because its checksum feature failed. + * + * @author Sean Owen + */ +public final class ChecksumException extends ReaderException { + + private static final ChecksumException instance = new ChecksumException(); + + private ChecksumException() { + // do nothing + } + + public static ChecksumException getChecksumInstance() { + return instance; + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/FormatException.java b/core/src/com/google/zxing/FormatException.java new file mode 100644 index 00000000..6967e93d --- /dev/null +++ b/core/src/com/google/zxing/FormatException.java @@ -0,0 +1,38 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing; + +/** + * Thrown when a barcode was successfully detected, but some aspect of + * the content did not conform to the barcode's format rules. This could have + * been due to a mis-detection. + * + * @author Sean Owen + */ +public final class FormatException extends ReaderException { + + private static final FormatException instance = new FormatException(); + + private FormatException() { + // do nothing + } + + public static FormatException getFormatInstance() { + return instance; + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/MultiFormatReader.java b/core/src/com/google/zxing/MultiFormatReader.java index 499ff747..6685882e 100644 --- a/core/src/com/google/zxing/MultiFormatReader.java +++ b/core/src/com/google/zxing/MultiFormatReader.java @@ -16,10 +16,10 @@ package com.google.zxing; +import com.google.zxing.datamatrix.DataMatrixReader; import com.google.zxing.oned.MultiFormatOneDReader; import com.google.zxing.pdf417.PDF417Reader; import com.google.zxing.qrcode.QRCodeReader; -import com.google.zxing.datamatrix.DataMatrixReader; import java.util.Hashtable; import java.util.Vector; @@ -44,9 +44,9 @@ public final class MultiFormatReader implements Reader { * * @param image The pixel data to decode * @return The contents of the image - * @throws ReaderException Any errors which occurred + * @throws NotFoundException Any errors which occurred */ - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) throws NotFoundException { setHints(null); return decodeInternal(image); } @@ -57,9 +57,9 @@ public final class MultiFormatReader implements Reader { * @param image The pixel data to decode * @param hints The hints to use, clearing the previous state. * @return The contents of the image - * @throws ReaderException Any errors which occurred + * @throws NotFoundException Any errors which occurred */ - public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException { + public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException { setHints(hints); return decodeInternal(image); } @@ -70,9 +70,9 @@ public final class MultiFormatReader implements Reader { * * @param image The pixel data to decode * @return The contents of the image - * @throws ReaderException Any errors which occurred + * @throws NotFoundException Any errors which occurred */ - public Result decodeWithState(BinaryBitmap image) throws ReaderException { + public Result decodeWithState(BinaryBitmap image) throws NotFoundException { // Make sure to set up the default state so we don't crash if (readers == null) { setHints(null); @@ -147,7 +147,7 @@ public final class MultiFormatReader implements Reader { } } - private Result decodeInternal(BinaryBitmap image) throws ReaderException { + private Result decodeInternal(BinaryBitmap image) throws NotFoundException { int size = readers.size(); for (int i = 0; i < size; i++) { Reader reader = (Reader) readers.elementAt(i); @@ -158,7 +158,7 @@ public final class MultiFormatReader implements Reader { } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } diff --git a/core/src/com/google/zxing/NotFoundException.java b/core/src/com/google/zxing/NotFoundException.java new file mode 100644 index 00000000..dedab8df --- /dev/null +++ b/core/src/com/google/zxing/NotFoundException.java @@ -0,0 +1,37 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing; + +/** + * Thrown when a barcode was not found in the image. It might have been + * partially detected but could not be confirmed. + * + * @author Sean Owen + */ +public final class NotFoundException extends ReaderException { + + private static final NotFoundException instance = new NotFoundException(); + + private NotFoundException() { + // do nothing + } + + public static NotFoundException getNotFoundInstance() { + return instance; + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/Reader.java b/core/src/com/google/zxing/Reader.java index cb745929..47e843ba 100644 --- a/core/src/com/google/zxing/Reader.java +++ b/core/src/com/google/zxing/Reader.java @@ -37,9 +37,9 @@ public interface Reader { * * @param image image of barcode to decode * @return String which the barcode encodes - * @throws ReaderException if the barcode cannot be located or decoded for any reason + * @throws NotFoundException if the barcode cannot be located or decoded for any reason */ - Result decode(BinaryBitmap image) throws ReaderException; + Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException; /** * Locates and decodes a barcode in some format within an image. This method also accepts @@ -51,9 +51,9 @@ public interface Reader { * meaning of the data depends upon the hint type. The implementation may or may not do * anything with these hints. * @return String which the barcode encodes - * @throws ReaderException if the barcode cannot be located or decoded for any reason + * @throws NotFoundException if the barcode cannot be located or decoded for any reason */ - Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException; + Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, ChecksumException, FormatException; /** * Resets any internal state the implementation has after a decode, to prepare it diff --git a/core/src/com/google/zxing/ReaderException.java b/core/src/com/google/zxing/ReaderException.java index 4e6a90f7..224a497e 100644 --- a/core/src/com/google/zxing/ReaderException.java +++ b/core/src/com/google/zxing/ReaderException.java @@ -23,7 +23,7 @@ package com.google.zxing; * * @author Sean Owen */ -public final class ReaderException extends Exception { +public abstract class ReaderException extends Exception { // TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before // rejecting it. This involves a lot of overhead and memory allocation, and affects both performance @@ -34,7 +34,7 @@ public final class ReaderException extends Exception { // by disabling the generation of stack traces, which is especially time consuming. These are just // temporary measures, pending the big cleanup. - private static final ReaderException instance = new ReaderException(); + //private static final ReaderException instance = new ReaderException(); // EXCEPTION TRACKING SUPPORT // Identifies who is throwing exceptions and how often. To use: @@ -45,11 +45,11 @@ public final class ReaderException extends Exception { // private static int exceptionCount = 0; // private static Map throwers = new HashMap(32); - private ReaderException() { + ReaderException() { // do nothing } - public static ReaderException getInstance() { + //public static ReaderException getInstance() { // Exception e = new Exception(); // // Take the stack frame before this one. // StackTraceElement stack = e.getStackTrace()[1]; @@ -64,8 +64,8 @@ public final class ReaderException extends Exception { // } // exceptionCount++; - return instance; - } + //return instance; + //} // public static int getExceptionCountAndReset() { // int temp = exceptionCount; @@ -91,7 +91,7 @@ public final class ReaderException extends Exception { // Prevent stack traces from being taken // srowen says: huh, my IDE is saying this is not an override. native methods can't be overridden? // This, at least, does not hurt. Because we use a singleton pattern here, it doesn't matter anyhow. - public Throwable fillInStackTrace() { + public final Throwable fillInStackTrace() { return null; } diff --git a/core/src/com/google/zxing/common/DefaultGridSampler.java b/core/src/com/google/zxing/common/DefaultGridSampler.java index f0a9e073..9a2a6831 100644 --- a/core/src/com/google/zxing/common/DefaultGridSampler.java +++ b/core/src/com/google/zxing/common/DefaultGridSampler.java @@ -16,7 +16,7 @@ package com.google.zxing.common; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; /** * @author Sean Owen @@ -32,7 +32,7 @@ public final class DefaultGridSampler extends GridSampler { float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, - float p4FromX, float p4FromY) throws ReaderException { + float p4FromX, float p4FromY) throws NotFoundException { PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral( p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, @@ -43,7 +43,7 @@ public final class DefaultGridSampler extends GridSampler { public BitMatrix sampleGrid(BitMatrix image, int dimension, - PerspectiveTransform transform) throws ReaderException { + PerspectiveTransform transform) throws NotFoundException { BitMatrix bits = new BitMatrix(dimension); float[] points = new float[dimension << 1]; for (int y = 0; y < dimension; y++) { @@ -72,7 +72,7 @@ public final class DefaultGridSampler extends GridSampler { // This results in an ugly runtime exception despite our clever checks above -- can't have // that. We could check each point's coordinates but that feels duplicative. We settle for // catching and wrapping ArrayIndexOutOfBoundsException. - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } return bits; diff --git a/core/src/com/google/zxing/common/GlobalHistogramBinarizer.java b/core/src/com/google/zxing/common/GlobalHistogramBinarizer.java index 015dfa93..144c0990 100644 --- a/core/src/com/google/zxing/common/GlobalHistogramBinarizer.java +++ b/core/src/com/google/zxing/common/GlobalHistogramBinarizer.java @@ -18,7 +18,7 @@ package com.google.zxing.common; import com.google.zxing.Binarizer; import com.google.zxing.LuminanceSource; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; /** * This Binarizer implementation uses the old ZXing global histogram approach. It is suitable @@ -45,7 +45,7 @@ public class GlobalHistogramBinarizer extends Binarizer { } // Applies simple sharpening to the row data to improve performance of the 1D Readers. - public BitArray getBlackRow(int y, BitArray row) throws ReaderException { + public BitArray getBlackRow(int y, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { @@ -79,7 +79,7 @@ public class GlobalHistogramBinarizer extends Binarizer { } // Does not sharpen the data, as this call is intended to only be used by 2D Readers. - public BitMatrix getBlackMatrix() throws ReaderException { + public BitMatrix getBlackMatrix() throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); int height = source.getHeight(); @@ -134,7 +134,7 @@ public class GlobalHistogramBinarizer extends Binarizer { } } - private static int estimateBlackPoint(int[] buckets) throws ReaderException { + private static int estimateBlackPoint(int[] buckets) throws NotFoundException { // Find the tallest peak in the histogram. int numBuckets = buckets.length; int maxBucketCount = 0; @@ -175,7 +175,7 @@ public class GlobalHistogramBinarizer extends Binarizer { // TODO: It might be worth comparing the brightest and darkest pixels seen, rather than the // two peaks, to determine the contrast. if (secondPeak - firstPeak <= numBuckets >> 4) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Find a valley between them that is low and closer to the white peak. diff --git a/core/src/com/google/zxing/common/GridSampler.java b/core/src/com/google/zxing/common/GridSampler.java index 5f2588fc..84024be4 100644 --- a/core/src/com/google/zxing/common/GridSampler.java +++ b/core/src/com/google/zxing/common/GridSampler.java @@ -16,7 +16,7 @@ package com.google.zxing.common; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; /** * Implementations of this class can, given locations of finder patterns for a QR code in an @@ -78,7 +78,7 @@ public abstract class GridSampler { * @param dimension width/height of {@link BitMatrix} to sample from image * @return {@link BitMatrix} representing a grid of points sampled from the image within a region * defined by the "from" parameters - * @throws ReaderException if image can't be sampled, for example, if the transformation defined + * @throws NotFoundException if image can't be sampled, for example, if the transformation defined * by the given points is invalid or results in sampling outside the image boundaries */ public abstract BitMatrix sampleGrid(BitMatrix image, @@ -90,11 +90,11 @@ public abstract class GridSampler { float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, - float p4FromX, float p4FromY) throws ReaderException; + float p4FromX, float p4FromY) throws NotFoundException; public BitMatrix sampleGrid(BitMatrix image, int dimension, - PerspectiveTransform transform) throws ReaderException { + PerspectiveTransform transform) throws NotFoundException { throw new UnsupportedOperationException(); } @@ -112,10 +112,10 @@ public abstract class GridSampler { * * @param image image into which the points should map * @param points actual points in x1,y1,...,xn,yn form - * @throws ReaderException if an endpoint is lies outside the image boundaries + * @throws NotFoundException if an endpoint is lies outside the image boundaries */ protected static void checkAndNudgePoints(BitMatrix image, float[] points) - throws ReaderException { + throws NotFoundException { int width = image.getWidth(); int height = image.getHeight(); // Check and nudge points from start until we see some that are OK: @@ -124,7 +124,7 @@ public abstract class GridSampler { int x = (int) points[offset]; int y = (int) points[offset + 1]; if (x < -1 || x > width || y < -1 || y > height) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } nudged = false; if (x == -1) { @@ -148,7 +148,7 @@ public abstract class GridSampler { int x = (int) points[offset]; int y = (int) points[offset + 1]; if (x < -1 || x > width || y < -1 || y > height) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } nudged = false; if (x == -1) { diff --git a/core/src/com/google/zxing/common/HybridBinarizer.java b/core/src/com/google/zxing/common/HybridBinarizer.java index d8681483..e6a6952f 100644 --- a/core/src/com/google/zxing/common/HybridBinarizer.java +++ b/core/src/com/google/zxing/common/HybridBinarizer.java @@ -18,7 +18,7 @@ package com.google.zxing.common; import com.google.zxing.Binarizer; import com.google.zxing.LuminanceSource; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; /** * This class implements a local thresholding algorithm, which while slower than the @@ -49,7 +49,7 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer { super(source); } - public BitMatrix getBlackMatrix() throws ReaderException { + public BitMatrix getBlackMatrix() throws NotFoundException { binarizeEntireImage(); return matrix; } @@ -61,7 +61,7 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer { // Calculates the final BitMatrix once for all requests. This could be called once from the // constructor instead, but there are some advantages to doing it lazily, such as making // profiling easier, and not doing heavy lifting when callers don't expect it. - private void binarizeEntireImage() throws ReaderException { + private void binarizeEntireImage() throws NotFoundException { if (matrix == null) { LuminanceSource source = getLuminanceSource(); if (source.getWidth() >= MINIMUM_DIMENSION && source.getHeight() >= MINIMUM_DIMENSION) { diff --git a/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java b/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java index 75eab7ac..950a2236 100644 --- a/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java +++ b/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java @@ -16,7 +16,7 @@ package com.google.zxing.common.detector; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; @@ -45,9 +45,9 @@ public final class MonochromeRectangleDetector { * last points are opposed on the diagonal, as are the second and third. The first point will be * the topmost point and the last, the bottommost. The second point will be leftmost and the * third, the rightmost - * @throws ReaderException if no Data Matrix Code can be found + * @throws NotFoundException if no Data Matrix Code can be found */ - public ResultPoint[] detect() throws ReaderException { + public ResultPoint[] detect() throws NotFoundException { int height = image.getHeight(); int width = image.getWidth(); int halfHeight = height >> 1; @@ -95,10 +95,10 @@ public final class MonochromeRectangleDetector { * @param maxWhiteRun maximum run of white pixels that can still be considered to be within * the barcode * @return a {@link com.google.zxing.ResultPoint} encapsulating the corner that was found - * @throws com.google.zxing.ReaderException if such a point cannot be found + * @throws NotFoundException if such a point cannot be found */ private ResultPoint findCornerFromCenter(int centerX, int deltaX, int left, int right, - int centerY, int deltaY, int top, int bottom, int maxWhiteRun) throws ReaderException { + int centerY, int deltaY, int top, int bottom, int maxWhiteRun) throws NotFoundException { int[] lastRange = null; for (int y = centerY, x = centerX; y < bottom && y >= top && x < right && x >= left; @@ -113,7 +113,7 @@ public final class MonochromeRectangleDetector { } if (range == null) { if (lastRange == null) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // lastRange was found if (deltaX == 0) { @@ -141,7 +141,7 @@ public final class MonochromeRectangleDetector { } lastRange = range; } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } /** diff --git a/core/src/com/google/zxing/datamatrix/DataMatrixReader.java b/core/src/com/google/zxing/datamatrix/DataMatrixReader.java index 30c2074d..01549172 100644 --- a/core/src/com/google/zxing/datamatrix/DataMatrixReader.java +++ b/core/src/com/google/zxing/datamatrix/DataMatrixReader.java @@ -17,13 +17,15 @@ package com.google.zxing.datamatrix; import com.google.zxing.BarcodeFormat; -import com.google.zxing.DecodeHintType; import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; +import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; -import com.google.zxing.ReaderException; import com.google.zxing.Result; -import com.google.zxing.ResultPoint; import com.google.zxing.ResultMetadataType; +import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.DetectorResult; @@ -47,14 +49,16 @@ public final class DataMatrixReader implements Reader { * Locates and decodes a Data Matrix code in an image. * * @return a String representing the content encoded by the Data Matrix code - * @throws ReaderException if a Data Matrix code cannot be found, or cannot be decoded + * @throws NotFoundException if a Data Matrix code cannot be found + * @throws FormatException if a Data Matrix code cannot be decoded + * @throws ChecksumException if error correction fails */ - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException { return decode(image, null); } public Result decode(BinaryBitmap image, Hashtable hints) - throws ReaderException { + throws NotFoundException, ChecksumException, FormatException { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) { @@ -86,7 +90,7 @@ public final class DataMatrixReader implements Reader { * around it. This is a specialized method that works exceptionally fast in this special * case. */ - private static BitMatrix extractPureBits(BitMatrix image) throws ReaderException { + private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException { // Now need to determine module size in pixels int height = image.getHeight(); @@ -99,7 +103,7 @@ public final class DataMatrixReader implements Reader { borderWidth++; } if (borderWidth == minDimension) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // And then keep tracking across the top-left black module to determine module size @@ -108,7 +112,7 @@ public final class DataMatrixReader implements Reader { moduleEnd++; } if (moduleEnd == width) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int moduleSize = moduleEnd - borderWidth; @@ -119,13 +123,13 @@ public final class DataMatrixReader implements Reader { columnEndOfSymbol--; } if (columnEndOfSymbol < 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } columnEndOfSymbol++; // Make sure width of barcode is a multiple of module size if ((columnEndOfSymbol - borderWidth) % moduleSize != 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int dimension = (columnEndOfSymbol - borderWidth) / moduleSize; @@ -136,7 +140,7 @@ public final class DataMatrixReader implements Reader { int sampleDimension = borderWidth + (dimension - 1) * moduleSize; if (sampleDimension >= width || sampleDimension >= height) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Now just read off the bits diff --git a/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java b/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java index 6536ebf0..849f5be0 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java @@ -16,7 +16,7 @@ package com.google.zxing.datamatrix.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitMatrix; /** @@ -30,12 +30,12 @@ final class BitMatrixParser { /** * @param bitMatrix {@link BitMatrix} to parse - * @throws ReaderException if dimension is < 10 or > 144 or not 0 mod 2 + * @throws FormatException if dimension is < 10 or > 144 or not 0 mod 2 */ - BitMatrixParser(BitMatrix bitMatrix) throws ReaderException { + BitMatrixParser(BitMatrix bitMatrix) throws FormatException { int dimension = bitMatrix.getDimension(); if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } version = readVersion(bitMatrix); @@ -52,10 +52,10 @@ final class BitMatrixParser { * * @param bitMatrix Original {@link BitMatrix} including alignment patterns * @return {@link Version} encapsulating the Data Matrix Code's "version" - * @throws ReaderException if the dimensions of the mapping matrix are not valid + * @throws FormatException if the dimensions of the mapping matrix are not valid * Data Matrix dimensions. */ - Version readVersion(BitMatrix bitMatrix) throws ReaderException { + Version readVersion(BitMatrix bitMatrix) throws FormatException { if (version != null) { return version; @@ -74,9 +74,9 @@ final class BitMatrixParser { * Data Matrix Code.

* * @return bytes encoded within the Data Matrix Code - * @throws ReaderException if the exact number of bytes expected is not read + * @throws FormatException if the exact number of bytes expected is not read */ - byte[] readCodewords() throws ReaderException { + byte[] readCodewords() throws FormatException { byte[] result = new byte[version.getTotalCodewords()]; int resultOffset = 0; @@ -141,7 +141,7 @@ final class BitMatrixParser { } while ((row < numRows) || (column < numColumns)); if (resultOffset != version.getTotalCodewords()) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } return result; } diff --git a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java index 7f6decab..d842f9c9 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java @@ -16,12 +16,12 @@ package com.google.zxing.datamatrix.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitSource; import com.google.zxing.common.DecoderResult; -import java.util.Vector; import java.io.UnsupportedEncodingException; +import java.util.Vector; /** *

Data Matrix Codes can encode text as bits in one of several modes, and can use multiple modes @@ -75,7 +75,7 @@ final class DecodedBitStreamParser { private DecodedBitStreamParser() { } - static DecoderResult decode(byte[] bytes) throws ReaderException { + static DecoderResult decode(byte[] bytes) throws FormatException { BitSource bits = new BitSource(bytes); StringBuffer result = new StringBuffer(100); StringBuffer resultTrailer = new StringBuffer(0); @@ -102,7 +102,7 @@ final class DecodedBitStreamParser { decodeBase256Segment(bits, result, byteSegments); break; default: - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } mode = ASCII_ENCODE; } @@ -117,12 +117,12 @@ final class DecodedBitStreamParser { * See ISO 16022:2006, 5.2.3 and Annex C, Table C.2 */ private static int decodeAsciiSegment(BitSource bits, StringBuffer result, StringBuffer resultTrailer) - throws ReaderException { + throws FormatException { boolean upperShift = false; do { int oneByte = bits.readBits(8); if (oneByte == 0) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } else if (oneByte <= 128) { // ASCII data (ASCII value + 1) oneByte = upperShift ? (oneByte + 128) : oneByte; upperShift = false; @@ -168,7 +168,7 @@ final class DecodedBitStreamParser { //throw ReaderException.getInstance(); // Ignore this symbol for now } else if (oneByte >= 242) { // Not to be used in ASCII encodation - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } while (bits.available() > 0); return ASCII_ENCODE; @@ -177,7 +177,7 @@ final class DecodedBitStreamParser { /** * See ISO 16022:2006, 5.2.5 and Annex C, Table C.1 */ - private static void decodeC40Segment(BitSource bits, StringBuffer result) throws ReaderException { + private static void decodeC40Segment(BitSource bits, StringBuffer result) throws FormatException { // Three C40 values are encoded in a 16-bit value as // (1600 * C1) + (40 * C2) + C3 + 1 // TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time @@ -230,11 +230,11 @@ final class DecodedBitStreamParser { result.append(C40_SHIFT2_SET_CHARS[cValue]); } } else if (cValue == 27) { // FNC1 - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } else if (cValue == 30) { // Upper Shift upperShift = true; } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } shift = 0; break; @@ -248,7 +248,7 @@ final class DecodedBitStreamParser { shift = 0; break; default: - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } } while (bits.available() > 0); @@ -257,7 +257,7 @@ final class DecodedBitStreamParser { /** * See ISO 16022:2006, 5.2.6 and Annex C, Table C.2 */ - private static void decodeTextSegment(BitSource bits, StringBuffer result) throws ReaderException { + private static void decodeTextSegment(BitSource bits, StringBuffer result) throws FormatException { // Three Text values are encoded in a 16-bit value as // (1600 * C1) + (40 * C2) + C3 + 1 // TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time @@ -311,11 +311,11 @@ final class DecodedBitStreamParser { result.append(C40_SHIFT2_SET_CHARS[cValue]); } } else if (cValue == 27) { // FNC1 - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } else if (cValue == 30) { // Upper Shift upperShift = true; } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } shift = 0; break; @@ -329,7 +329,7 @@ final class DecodedBitStreamParser { shift = 0; break; default: - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } } while (bits.available() > 0); @@ -338,7 +338,7 @@ final class DecodedBitStreamParser { /** * See ISO 16022:2006, 5.2.7 */ - private static void decodeAnsiX12Segment(BitSource bits, StringBuffer result) throws ReaderException { + private static void decodeAnsiX12Segment(BitSource bits, StringBuffer result) throws FormatException { // Three ANSI X12 values are encoded in a 16-bit value as // (1600 * C1) + (40 * C2) + C3 + 1 @@ -370,7 +370,7 @@ final class DecodedBitStreamParser { } else if (cValue < 40) { // A - Z result.append((char) (cValue + 51)); } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } } while (bits.available() > 0); diff --git a/core/src/com/google/zxing/datamatrix/decoder/Decoder.java b/core/src/com/google/zxing/datamatrix/decoder/Decoder.java index 5b1e5db4..58f8c98a 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/Decoder.java +++ b/core/src/com/google/zxing/datamatrix/decoder/Decoder.java @@ -16,7 +16,8 @@ package com.google.zxing.datamatrix.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.reedsolomon.GF256; @@ -43,9 +44,10 @@ public final class Decoder { * * @param image booleans representing white/black Data Matrix Code modules * @return text and bytes encoded within the Data Matrix Code - * @throws ReaderException if the Data Matrix Code cannot be decoded + * @throws FormatException if the Data Matrix Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(boolean[][] image) throws ReaderException { + public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException { int dimension = image.length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { @@ -64,9 +66,10 @@ public final class Decoder { * * @param bits booleans representing white/black Data Matrix Code modules * @return text and bytes encoded within the Data Matrix Code - * @throws ReaderException if the Data Matrix Code cannot be decoded + * @throws FormatException if the Data Matrix Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(BitMatrix bits) throws ReaderException { + public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException { // Construct a parser and read version, error-correction level BitMatrixParser parser = new BitMatrixParser(bits); @@ -106,9 +109,9 @@ public final class Decoder { * * @param codewordBytes data and error correction codewords * @param numDataCodewords number of codewords that are data bytes - * @throws ReaderException if error correction fails + * @throws ChecksumException if error correction fails */ - private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException { + 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]; @@ -119,7 +122,7 @@ public final class Decoder { try { rsDecoder.decode(codewordsInts, numECCodewords); } catch (ReedSolomonException rse) { - throw ReaderException.getInstance(); + 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 diff --git a/core/src/com/google/zxing/datamatrix/decoder/Version.java b/core/src/com/google/zxing/datamatrix/decoder/Version.java index 2a941d1d..d2b712bb 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/Version.java +++ b/core/src/com/google/zxing/datamatrix/decoder/Version.java @@ -16,7 +16,7 @@ package com.google.zxing.datamatrix.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; /** * The Version object encapsulates attributes about a particular @@ -94,11 +94,11 @@ public final class Version { * @param numRows Number of rows in modules * @param numColumns Number of columns in modules * @return {@link Version} for a Data Matrix Code of those dimensions - * @throws ReaderException if dimensions do correspond to a valid Data Matrix size + * @throws FormatException if dimensions do correspond to a valid Data Matrix size */ - public static Version getVersionForDimensions(int numRows, int numColumns) throws ReaderException { + public static Version getVersionForDimensions(int numRows, int numColumns) throws FormatException { if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } // TODO(bbrown): This is doing a linear search through the array of versions. @@ -112,7 +112,7 @@ public final class Version { } } - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } /** diff --git a/core/src/com/google/zxing/datamatrix/detector/Detector.java b/core/src/com/google/zxing/datamatrix/detector/Detector.java index 823c6242..5915865a 100644 --- a/core/src/com/google/zxing/datamatrix/detector/Detector.java +++ b/core/src/com/google/zxing/datamatrix/detector/Detector.java @@ -16,7 +16,7 @@ package com.google.zxing.datamatrix.detector; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.Collections; @@ -57,9 +57,9 @@ public final class Detector { *

Detects a Data Matrix Code in an image.

* * @return {@link DetectorResult} encapsulating results of detecting a QR Code - * @throws ReaderException if no Data Matrix Code can be found + * @throws NotFoundException if no Data Matrix Code can be found */ - public DetectorResult detect() throws ReaderException { + public DetectorResult detect() throws NotFoundException { ResultPoint[] cornerPoints = rectangleDetector.detect(); ResultPoint pointA = cornerPoints[0]; @@ -110,7 +110,7 @@ public final class Detector { } if (maybeTopLeft == null || bottomLeft == null || maybeBottomRight == null) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Bottom left is correct but top left and bottom right might be switched @@ -169,7 +169,7 @@ public final class Detector { ResultPoint topLeft, ResultPoint bottomLeft, ResultPoint bottomRight, - int dimension) throws ReaderException { + int dimension) throws NotFoundException { // We make up the top right point for now, based on the others. // TODO: we actually found a fourth corner above and figured out which of two modules diff --git a/core/src/com/google/zxing/multi/ByQuadrantReader.java b/core/src/com/google/zxing/multi/ByQuadrantReader.java index aaf1afba..35904d36 100644 --- a/core/src/com/google/zxing/multi/ByQuadrantReader.java +++ b/core/src/com/google/zxing/multi/ByQuadrantReader.java @@ -17,8 +17,10 @@ package com.google.zxing.multi; import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; -import com.google.zxing.ReaderException; import com.google.zxing.Result; import java.util.Hashtable; @@ -40,11 +42,13 @@ public final class ByQuadrantReader implements Reader { this.delegate = delegate; } - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) + throws NotFoundException, ChecksumException, FormatException { return decode(image, null); } - public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException { + public Result decode(BinaryBitmap image, Hashtable hints) + throws NotFoundException, ChecksumException, FormatException { int width = image.getWidth(); int height = image.getHeight(); @@ -54,28 +58,28 @@ public final class ByQuadrantReader implements Reader { BinaryBitmap topLeft = image.crop(0, 0, halfWidth, halfHeight); try { return delegate.decode(topLeft, hints); - } catch (ReaderException re) { + } catch (NotFoundException re) { // continue } BinaryBitmap topRight = image.crop(halfWidth, 0, halfWidth, halfHeight); try { return delegate.decode(topRight, hints); - } catch (ReaderException re) { + } catch (NotFoundException re) { // continue } BinaryBitmap bottomLeft = image.crop(0, halfHeight, halfWidth, halfHeight); try { return delegate.decode(bottomLeft, hints); - } catch (ReaderException re) { + } catch (NotFoundException re) { // continue } BinaryBitmap bottomRight = image.crop(halfWidth, halfHeight, halfWidth, halfHeight); try { return delegate.decode(bottomRight, hints); - } catch (ReaderException re) { + } catch (NotFoundException re) { // continue } diff --git a/core/src/com/google/zxing/multi/GenericMultipleBarcodeReader.java b/core/src/com/google/zxing/multi/GenericMultipleBarcodeReader.java index 87605283..a6ace112 100644 --- a/core/src/com/google/zxing/multi/GenericMultipleBarcodeReader.java +++ b/core/src/com/google/zxing/multi/GenericMultipleBarcodeReader.java @@ -16,10 +16,11 @@ package com.google.zxing.multi; -import com.google.zxing.Reader; -import com.google.zxing.Result; import com.google.zxing.BinaryBitmap; +import com.google.zxing.NotFoundException; +import com.google.zxing.Reader; import com.google.zxing.ReaderException; +import com.google.zxing.Result; import com.google.zxing.ResultPoint; import java.util.Hashtable; @@ -49,16 +50,16 @@ public final class GenericMultipleBarcodeReader implements MultipleBarcodeReader this.delegate = delegate; } - public Result[] decodeMultiple(BinaryBitmap image) throws ReaderException { + public Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException { return decodeMultiple(image, null); } public Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) - throws ReaderException { + throws NotFoundException { Vector results = new Vector(); doDecodeMultiple(image, hints, results, 0, 0); if (results.isEmpty()) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int numResults = results.size(); Result[] resultArray = new Result[numResults]; diff --git a/core/src/com/google/zxing/multi/MultipleBarcodeReader.java b/core/src/com/google/zxing/multi/MultipleBarcodeReader.java index c3b43102..5f0c7eb5 100644 --- a/core/src/com/google/zxing/multi/MultipleBarcodeReader.java +++ b/core/src/com/google/zxing/multi/MultipleBarcodeReader.java @@ -16,9 +16,9 @@ package com.google.zxing.multi; -import com.google.zxing.Result; import com.google.zxing.BinaryBitmap; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; +import com.google.zxing.Result; import java.util.Hashtable; @@ -30,8 +30,8 @@ import java.util.Hashtable; */ public interface MultipleBarcodeReader { - Result[] decodeMultiple(BinaryBitmap image) throws ReaderException; + Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException; - Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws ReaderException; + Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws NotFoundException; } diff --git a/core/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java b/core/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java index 191a7142..72a7d681 100644 --- a/core/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java +++ b/core/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java @@ -18,6 +18,7 @@ package com.google.zxing.multi.qrcode; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; +import com.google.zxing.NotFoundException; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.ResultMetadataType; @@ -41,11 +42,11 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar private static final Result[] EMPTY_RESULT_ARRAY = new Result[0]; - public Result[] decodeMultiple(BinaryBitmap image) throws ReaderException { + public Result[] decodeMultiple(BinaryBitmap image) throws NotFoundException { return decodeMultiple(image, null); } - public Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws ReaderException { + public Result[] decodeMultiple(BinaryBitmap image, Hashtable hints) throws NotFoundException { Vector results = new Vector(); DetectorResult[] detectorResult = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (int i = 0; i < detectorResult.length; i++) { diff --git a/core/src/com/google/zxing/multi/qrcode/detector/MultiDetector.java b/core/src/com/google/zxing/multi/qrcode/detector/MultiDetector.java index 8ce4d43a..d3797d9e 100644 --- a/core/src/com/google/zxing/multi/qrcode/detector/MultiDetector.java +++ b/core/src/com/google/zxing/multi/qrcode/detector/MultiDetector.java @@ -16,9 +16,10 @@ package com.google.zxing.multi.qrcode.detector; -import com.google.zxing.ReaderException; -import com.google.zxing.common.DetectorResult; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitMatrix; +import com.google.zxing.common.DetectorResult; import com.google.zxing.qrcode.detector.Detector; import com.google.zxing.qrcode.detector.FinderPatternInfo; @@ -40,20 +41,20 @@ public final class MultiDetector extends Detector { super(image); } - public DetectorResult[] detectMulti(Hashtable hints) throws ReaderException { + public DetectorResult[] detectMulti(Hashtable hints) throws NotFoundException { BitMatrix image = getImage(); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image); FinderPatternInfo[] info = finder.findMulti(hints); if (info == null || info.length == 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } Vector result = new Vector(); for (int i = 0; i < info.length; i++) { try { result.addElement(processFinderPatternInfo(info[i])); - } catch (ReaderException e) { + } catch (FormatException e) { // ignore } } diff --git a/core/src/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java b/core/src/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java index d1334005..0eb8ea10 100644 --- a/core/src/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java +++ b/core/src/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java @@ -17,12 +17,12 @@ package com.google.zxing.multi.qrcode.detector; import com.google.zxing.DecodeHintType; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.ResultPointCallback; +import com.google.zxing.common.BitMatrix; import com.google.zxing.common.Collections; import com.google.zxing.common.Comparator; -import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.detector.FinderPattern; import com.google.zxing.qrcode.detector.FinderPatternFinder; import com.google.zxing.qrcode.detector.FinderPatternInfo; @@ -99,15 +99,15 @@ final class MultiFinderPatternFinder extends FinderPatternFinder { * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are * those that have been detected at least {@link #CENTER_QUORUM} times, and whose module * size differs from the average among those patterns the least - * @throws ReaderException if 3 such finder patterns do not exist + * @throws NotFoundException if 3 such finder patterns do not exist */ - private FinderPattern[][] selectBestPatterns() throws ReaderException { + private FinderPattern[][] selectBestPatterns() throws NotFoundException { Vector possibleCenters = getPossibleCenters(); int size = possibleCenters.size(); if (size < 3) { // Couldn't find enough finder patterns - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } /* @@ -227,10 +227,10 @@ final class MultiFinderPatternFinder extends FinderPatternFinder { } // Nothing found! - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } - public FinderPatternInfo[] findMulti(Hashtable hints) throws ReaderException { + public FinderPatternInfo[] findMulti(Hashtable hints) throws NotFoundException { boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); BitMatrix image = getImage(); int maxI = image.getHeight(); diff --git a/core/src/com/google/zxing/oned/Code128Reader.java b/core/src/com/google/zxing/oned/Code128Reader.java index 981835b0..e87bd712 100644 --- a/core/src/com/google/zxing/oned/Code128Reader.java +++ b/core/src/com/google/zxing/oned/Code128Reader.java @@ -17,7 +17,9 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitArray; @@ -161,7 +163,7 @@ public final class Code128Reader extends OneDReader { private static final int CODE_START_C = 105; private static final int CODE_STOP = 106; - private static int[] findStartPattern(BitArray row) throws ReaderException { + private static int[] findStartPattern(BitArray row) throws NotFoundException { int width = row.getSize(); int rowOffset = 0; while (rowOffset < width) { @@ -214,10 +216,10 @@ public final class Code128Reader extends OneDReader { isWhite = !isWhite; } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } - private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws ReaderException { + private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws NotFoundException { recordPattern(row, rowOffset, counters); int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; @@ -233,11 +235,12 @@ public final class Code128Reader extends OneDReader { if (bestMatch >= 0) { return bestMatch; } else { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) + throws NotFoundException, FormatException, ChecksumException { int[] startPatternInfo = findStartPattern(row); int startCode = startPatternInfo[2]; @@ -253,7 +256,7 @@ public final class Code128Reader extends OneDReader { codeSet = CODE_CODE_C; break; default: - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } boolean done = false; @@ -303,7 +306,7 @@ public final class Code128Reader extends OneDReader { case CODE_START_A: case CODE_START_B: case CODE_START_C: - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } switch (codeSet) { @@ -426,14 +429,14 @@ public final class Code128Reader extends OneDReader { } if (!row.isRange(nextStart, Math.min(width, nextStart + (nextStart - lastStart) / 2), false)) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Pull out from sum the value of the penultimate check code checksumTotal -= multiplier * lastCode; // lastCode is the checksum then: if (checksumTotal % 103 != lastCode) { - throw ReaderException.getInstance(); + throw ChecksumException.getChecksumInstance(); } // Need to pull out the check digits from string @@ -452,7 +455,7 @@ public final class Code128Reader extends OneDReader { if (resultString.length() == 0) { // Almost surely a false positive - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f; diff --git a/core/src/com/google/zxing/oned/Code39Reader.java b/core/src/com/google/zxing/oned/Code39Reader.java index 36b74461..c997ec6d 100644 --- a/core/src/com/google/zxing/oned/Code39Reader.java +++ b/core/src/com/google/zxing/oned/Code39Reader.java @@ -17,7 +17,9 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitArray; @@ -88,7 +90,8 @@ public final class Code39Reader extends OneDReader { this.extendedMode = extendedMode; } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) + throws NotFoundException, ChecksumException, FormatException { int[] start = findAsteriskPattern(row); int nextStart = start[1]; @@ -107,7 +110,7 @@ public final class Code39Reader extends OneDReader { recordPattern(row, nextStart, counters); int pattern = toNarrowWidePattern(counters); if (pattern < 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } decodedChar = patternToChar(pattern); result.append(decodedChar); @@ -131,7 +134,7 @@ public final class Code39Reader extends OneDReader { // If 50% of last pattern size, following last pattern, is not whitespace, fail // (but if it's whitespace to the very end of the image, that's OK) if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } if (usingCheckDigit) { @@ -141,7 +144,7 @@ public final class Code39Reader extends OneDReader { total += ALPHABET_STRING.indexOf(result.charAt(i)); } if (total % 43 != ALPHABET_STRING.indexOf(result.charAt(max))) { - throw ReaderException.getInstance(); + throw ChecksumException.getChecksumInstance(); } result.deleteCharAt(max); } @@ -153,7 +156,7 @@ public final class Code39Reader extends OneDReader { if (resultString.length() == 0) { // Almost surely a false positive - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } float left = (float) (start[1] + start[0]) / 2.0f; @@ -168,7 +171,7 @@ public final class Code39Reader extends OneDReader { } - private static int[] findAsteriskPattern(BitArray row) throws ReaderException { + private static int[] findAsteriskPattern(BitArray row) throws NotFoundException { int width = row.getSize(); int rowOffset = 0; while (rowOffset < width) { @@ -210,7 +213,7 @@ public final class Code39Reader extends OneDReader { isWhite = !isWhite; } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // For efficiency, returns -1 on failure. Not throwing here saved as many as 700 exceptions @@ -259,16 +262,16 @@ public final class Code39Reader extends OneDReader { return -1; } - private static char patternToChar(int pattern) throws ReaderException { + private static char patternToChar(int pattern) throws NotFoundException { for (int i = 0; i < CHARACTER_ENCODINGS.length; i++) { if (CHARACTER_ENCODINGS[i] == pattern) { return ALPHABET[i]; } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } - private static String decodeExtended(String encoded) throws ReaderException { + private static String decodeExtended(String encoded) throws FormatException { int length = encoded.length(); StringBuffer decoded = new StringBuffer(length); for (int i = 0; i < length; i++) { @@ -282,7 +285,7 @@ public final class Code39Reader extends OneDReader { if (next >= 'A' && next <= 'Z') { decodedChar = (char) (next + 32); } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } break; case '$': @@ -290,7 +293,7 @@ public final class Code39Reader extends OneDReader { if (next >= 'A' && next <= 'Z') { decodedChar = (char) (next - 64); } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } break; case '%': @@ -300,7 +303,7 @@ public final class Code39Reader extends OneDReader { } else if (next >= 'F' && next <= 'W') { decodedChar = (char) (next - 11); } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } break; case '/': @@ -310,7 +313,7 @@ public final class Code39Reader extends OneDReader { } else if (next == 'Z') { decodedChar = ':'; } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } break; } diff --git a/core/src/com/google/zxing/oned/EAN13Reader.java b/core/src/com/google/zxing/oned/EAN13Reader.java index 67d82a85..9c90e83e 100644 --- a/core/src/com/google/zxing/oned/EAN13Reader.java +++ b/core/src/com/google/zxing/oned/EAN13Reader.java @@ -17,7 +17,7 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitArray; /** @@ -69,7 +69,7 @@ public final class EAN13Reader extends UPCEANReader { } protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString) - throws ReaderException { + throws NotFoundException { int[] counters = decodeMiddleCounters; counters[0] = 0; counters[1] = 0; @@ -119,17 +119,17 @@ public final class EAN13Reader extends UPCEANReader { * @param resultString string to insert decoded first digit into * @param lgPatternFound int whose bits indicates the pattern of odd/even L/G patterns used to * encode digits - * @throws ReaderException if first digit cannot be determined + * @throws NotFoundException if first digit cannot be determined */ private static void determineFirstDigit(StringBuffer resultString, int lgPatternFound) - throws ReaderException { + throws NotFoundException { for (int d = 0; d < 10; d++) { if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) { resultString.insert(0, (char) ('0' + d)); return; } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } diff --git a/core/src/com/google/zxing/oned/EAN8Reader.java b/core/src/com/google/zxing/oned/EAN8Reader.java index 3e64ea6d..30fbacba 100644 --- a/core/src/com/google/zxing/oned/EAN8Reader.java +++ b/core/src/com/google/zxing/oned/EAN8Reader.java @@ -17,7 +17,7 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitArray; /** @@ -34,7 +34,7 @@ public final class EAN8Reader extends UPCEANReader { } protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result) - throws ReaderException { + throws NotFoundException { int[] counters = decodeMiddleCounters; counters[0] = 0; counters[1] = 0; diff --git a/core/src/com/google/zxing/oned/ITFReader.java b/core/src/com/google/zxing/oned/ITFReader.java index 93c82dd2..9a0a9416 100644 --- a/core/src/com/google/zxing/oned/ITFReader.java +++ b/core/src/com/google/zxing/oned/ITFReader.java @@ -18,7 +18,8 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; import com.google.zxing.DecodeHintType; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitArray; @@ -75,7 +76,7 @@ public final class ITFReader extends OneDReader { {N, W, N, W, N} // 9 }; - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws FormatException, NotFoundException { // Find out where the Middle section (payload) starts & ends int[] startRange = decodeStart(row); @@ -106,7 +107,7 @@ public final class ITFReader extends OneDReader { } if (!lengthOK) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } return new Result( @@ -121,10 +122,10 @@ public final class ITFReader extends OneDReader { * @param row row of black/white values to search * @param payloadStart offset of start pattern * @param resultString {@link StringBuffer} to append decoded chars to - * @throws ReaderException if decoding could not complete successfully + * @throws NotFoundException if decoding could not complete successfully */ private static void decodeMiddle(BitArray row, int payloadStart, int payloadEnd, - StringBuffer resultString) throws ReaderException { + StringBuffer resultString) throws NotFoundException { // Digits are interleaved in pairs - 5 black lines for one digit, and the // 5 @@ -163,9 +164,9 @@ public final class ITFReader extends OneDReader { * @param row row of black/white values to search * @return Array, containing index of start of 'start block' and end of * 'start block' - * @throws ReaderException + * @throws NotFoundException */ - int[] decodeStart(BitArray row) throws ReaderException { + int[] decodeStart(BitArray row) throws NotFoundException { int endStart = skipWhiteSpace(row); int[] startPattern = findGuardPattern(row, endStart, START_PATTERN); @@ -192,9 +193,9 @@ public final class ITFReader extends OneDReader { * * @param row bit array representing the scanned barcode. * @param startPattern index into row of the start or end pattern. - * @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown. + * @throws NotFoundException if the quiet zone cannot be found, a ReaderException is thrown. */ - private void validateQuietZone(BitArray row, int startPattern) throws ReaderException { + private void validateQuietZone(BitArray row, int startPattern) throws NotFoundException { int quietCount = this.narrowLineWidth * 10; // expect to find this many pixels of quiet zone @@ -206,7 +207,7 @@ public final class ITFReader extends OneDReader { } if (quietCount != 0) { // Unable to find the necessary number of quiet zone pixels. - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } @@ -215,9 +216,9 @@ public final class ITFReader extends OneDReader { * * @param row row of black/white values to search * @return index of the first black line. - * @throws ReaderException Throws exception if no black lines are found in the row + * @throws NotFoundException Throws exception if no black lines are found in the row */ - private static int skipWhiteSpace(BitArray row) throws ReaderException { + private static int skipWhiteSpace(BitArray row) throws NotFoundException { int width = row.getSize(); int endStart = 0; while (endStart < width) { @@ -227,7 +228,7 @@ public final class ITFReader extends OneDReader { endStart++; } if (endStart == width) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } return endStart; @@ -239,10 +240,10 @@ public final class ITFReader extends OneDReader { * @param row row of black/white values to search * @return Array, containing index of start of 'end block' and end of 'end * block' - * @throws ReaderException + * @throws NotFoundException */ - int[] decodeEnd(BitArray row) throws ReaderException { + int[] decodeEnd(BitArray row) throws NotFoundException { // For convenience, reverse the row and then // search from 'the start' for the end block @@ -277,9 +278,9 @@ public final class ITFReader extends OneDReader { * being searched for as a pattern * @return start/end horizontal offset of guard pattern, as an array of two * ints - * @throws ReaderException if pattern is not found + * @throws NotFoundException if pattern is not found */ - private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException { + private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws NotFoundException { // TODO: This is very similar to implementation in UPCEANReader. Consider if they can be // merged to a single method. @@ -313,7 +314,7 @@ public final class ITFReader extends OneDReader { isWhite = !isWhite; } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } /** @@ -322,9 +323,9 @@ public final class ITFReader extends OneDReader { * * @param counters the counts of runs of observed black/white/black/... values * @return The decoded digit - * @throws ReaderException if digit cannot be decoded + * @throws NotFoundException if digit cannot be decoded */ - private static int decodeDigit(int[] counters) throws ReaderException { + private static int decodeDigit(int[] counters) throws NotFoundException { int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; @@ -340,7 +341,7 @@ public final class ITFReader extends OneDReader { if (bestMatch >= 0) { return bestMatch; } else { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } diff --git a/core/src/com/google/zxing/oned/MultiFormatOneDReader.java b/core/src/com/google/zxing/oned/MultiFormatOneDReader.java index ccdbe6d0..40e4a8b7 100644 --- a/core/src/com/google/zxing/oned/MultiFormatOneDReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatOneDReader.java @@ -18,11 +18,11 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; import com.google.zxing.DecodeHintType; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.common.BitArray; -import com.google.zxing.oned.rss.RSS14Reader; import java.util.Hashtable; import java.util.Vector; @@ -70,7 +70,7 @@ public final class MultiFormatOneDReader extends OneDReader { } } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException { int size = readers.size(); for (int i = 0; i < size; i++) { OneDReader reader = (OneDReader) readers.elementAt(i); @@ -81,7 +81,7 @@ public final class MultiFormatOneDReader extends OneDReader { } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } public void reset() { diff --git a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java index dcc32be3..4524f3e3 100644 --- a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java @@ -18,6 +18,7 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; import com.google.zxing.DecodeHintType; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; @@ -62,7 +63,7 @@ public final class MultiFormatUPCEANReader extends OneDReader { } } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException { // Compute this location once and reuse it on multiple implementations int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row); int size = readers.size(); @@ -92,7 +93,7 @@ public final class MultiFormatUPCEANReader extends OneDReader { return result; } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } public void reset() { diff --git a/core/src/com/google/zxing/oned/OneDReader.java b/core/src/com/google/zxing/oned/OneDReader.java index b21e9af8..fc8bd8d3 100644 --- a/core/src/com/google/zxing/oned/OneDReader.java +++ b/core/src/com/google/zxing/oned/OneDReader.java @@ -17,7 +17,10 @@ package com.google.zxing.oned; import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; @@ -40,15 +43,15 @@ public abstract class OneDReader implements Reader { private static final int INTEGER_MATH_SHIFT = 8; protected static final int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT; - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) throws NotFoundException, FormatException { return decode(image, null); } // Note that we don't try rotation without the try harder flag, even if rotation was supported. - public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException { + public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, FormatException { try { return doDecode(image, hints); - } catch (ReaderException re) { + } catch (NotFoundException nfe) { boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); if (tryHarder && image.isRotateSupported()) { BinaryBitmap rotatedImage = image.rotateCounterClockwise(); @@ -70,7 +73,7 @@ public abstract class OneDReader implements Reader { } return result; } else { - throw re; + throw nfe; } } } @@ -91,9 +94,9 @@ public abstract class OneDReader implements Reader { * @param image The image to decode * @param hints Any hints that were requested * @return The contents of the decoded barcode - * @throws ReaderException Any spontaneous errors which occur + * @throws NotFoundException Any spontaneous errors which occur */ - private Result doDecode(BinaryBitmap image, Hashtable hints) throws ReaderException { + private Result doDecode(BinaryBitmap image, Hashtable hints) throws NotFoundException { int width = image.getWidth(); int height = image.getHeight(); BitArray row = new BitArray(width); @@ -122,7 +125,7 @@ public abstract class OneDReader implements Reader { // Estimate black point for this row and load it: try { row = image.getBlackRow(rowNumber, row); - } catch (ReaderException re) { + } catch (NotFoundException nfe) { continue; } @@ -166,7 +169,7 @@ public abstract class OneDReader implements Reader { } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } /** @@ -179,17 +182,17 @@ public abstract class OneDReader implements Reader { * @param row row to count from * @param start offset into row to start at * @param counters array into which to record counts - * @throws ReaderException if counters cannot be filled entirely from row before running out + * @throws NotFoundException if counters cannot be filled entirely from row before running out * of pixels */ - protected static void recordPattern(BitArray row, int start, int[] counters) throws ReaderException { + protected static void recordPattern(BitArray row, int start, int[] counters) throws NotFoundException { int numCounters = counters.length; for (int i = 0; i < numCounters; i++) { counters[i] = 0; } int end = row.getSize(); if (start >= end) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } boolean isWhite = !row.get(start); int counterPosition = 0; @@ -212,12 +215,12 @@ public abstract class OneDReader implements Reader { // If we read fully the last section of pixels and filled up our counters -- or filled // the last counter but ran off the side of the image, OK. Otherwise, a problem. if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } protected static void recordPatternInReverse(BitArray row, int start, int[] counters) - throws ReaderException { + throws NotFoundException { // This could be more efficient I guess int numTransitionsLeft = counters.length; boolean last = row.get(start); @@ -228,7 +231,7 @@ public abstract class OneDReader implements Reader { } } if (numTransitionsLeft >= 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } recordPattern(row, start + 1, counters); } @@ -286,9 +289,9 @@ public abstract class OneDReader implements Reader { * @param row the black/white pixel data of the row * @param hints decode hints * @return {@link Result} containing encoded string and start/end of barcode - * @throws ReaderException if an error occurs or barcode cannot be found + * @throws NotFoundException if an error occurs or barcode cannot be found */ public abstract Result decodeRow(int rowNumber, BitArray row, Hashtable hints) - throws ReaderException; + throws NotFoundException, ChecksumException, FormatException; } diff --git a/core/src/com/google/zxing/oned/UPCAReader.java b/core/src/com/google/zxing/oned/UPCAReader.java index 9b5e9cbe..b90c1b87 100644 --- a/core/src/com/google/zxing/oned/UPCAReader.java +++ b/core/src/com/google/zxing/oned/UPCAReader.java @@ -17,9 +17,11 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; -import com.google.zxing.ReaderException; -import com.google.zxing.Result; import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; +import com.google.zxing.Result; import com.google.zxing.common.BitArray; import java.util.Hashtable; @@ -35,19 +37,20 @@ public final class UPCAReader extends UPCEANReader { private final UPCEANReader ean13Reader = new EAN13Reader(); public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Hashtable hints) - throws ReaderException { + throws NotFoundException, FormatException, ChecksumException { return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints)); } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) + throws NotFoundException, FormatException, ChecksumException { return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, hints)); } - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) throws NotFoundException, FormatException { return maybeReturnResult(ean13Reader.decode(image)); } - public Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException { + public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, FormatException { return maybeReturnResult(ean13Reader.decode(image, hints)); } @@ -56,16 +59,16 @@ public final class UPCAReader extends UPCEANReader { } protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString) - throws ReaderException { + throws NotFoundException { return ean13Reader.decodeMiddle(row, startRange, resultString); } - private static Result maybeReturnResult(Result result) throws ReaderException { + private static Result maybeReturnResult(Result result) throws FormatException { String text = result.getText(); if (text.charAt(0) == '0') { return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A); } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } diff --git a/core/src/com/google/zxing/oned/UPCEANReader.java b/core/src/com/google/zxing/oned/UPCEANReader.java index be490277..803eaa6c 100644 --- a/core/src/com/google/zxing/oned/UPCEANReader.java +++ b/core/src/com/google/zxing/oned/UPCEANReader.java @@ -16,12 +16,14 @@ package com.google.zxing.oned; -import com.google.zxing.ReaderException; -import com.google.zxing.Result; -import com.google.zxing.ResultPointCallback; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.ChecksumException; import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; +import com.google.zxing.Result; import com.google.zxing.ResultPoint; -import com.google.zxing.BarcodeFormat; +import com.google.zxing.ResultPointCallback; import com.google.zxing.common.BitArray; import java.util.Hashtable; @@ -94,7 +96,7 @@ public abstract class UPCEANReader extends OneDReader { decodeRowStringBuffer = new StringBuffer(20); } - static int[] findStartGuardPattern(BitArray row) throws ReaderException { + static int[] findStartGuardPattern(BitArray row) throws NotFoundException { boolean foundStart = false; int[] startRange = null; int nextStart = 0; @@ -113,7 +115,8 @@ public abstract class UPCEANReader extends OneDReader { return startRange; } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) + throws NotFoundException, ChecksumException, FormatException { return decodeRow(rowNumber, row, findStartGuardPattern(row), hints); } @@ -123,7 +126,7 @@ public abstract class UPCEANReader extends OneDReader { * found. This allows this to be computed once and reused across many implementations.

*/ public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Hashtable hints) - throws ReaderException { + throws NotFoundException, ChecksumException, FormatException { ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); @@ -158,12 +161,12 @@ public abstract class UPCEANReader extends OneDReader { int end = endRange[1]; int quietEnd = end + (end - endRange[0]); if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } String resultString = result.toString(); if (!checkChecksum(resultString)) { - throw ReaderException.getInstance(); + throw ChecksumException.getChecksumInstance(); } float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f; @@ -179,7 +182,7 @@ public abstract class UPCEANReader extends OneDReader { /** * @return {@link #checkStandardUPCEANChecksum(String)} */ - boolean checkChecksum(String s) throws ReaderException { + boolean checkChecksum(String s) throws ChecksumException, FormatException { return checkStandardUPCEANChecksum(s); } @@ -189,9 +192,10 @@ public abstract class UPCEANReader extends OneDReader { * * @param s string of digits to check * @return true iff string of digits passes the UPC/EAN checksum algorithm - * @throws ReaderException if the string does not contain only digits + * @throws FormatException if the string does not contain only digits + * @throws ChecksumException if checksum mismatches */ - private static boolean checkStandardUPCEANChecksum(String s) throws ReaderException { + private static boolean checkStandardUPCEANChecksum(String s) throws ChecksumException, FormatException { int length = s.length(); if (length == 0) { return false; @@ -201,7 +205,7 @@ public abstract class UPCEANReader extends OneDReader { for (int i = length - 2; i >= 0; i -= 2) { int digit = (int) s.charAt(i) - (int) '0'; if (digit < 0 || digit > 9) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } sum += digit; } @@ -209,14 +213,14 @@ public abstract class UPCEANReader extends OneDReader { for (int i = length - 1; i >= 0; i -= 2) { int digit = (int) s.charAt(i) - (int) '0'; if (digit < 0 || digit > 9) { - throw ReaderException.getInstance(); + throw ChecksumException.getChecksumInstance(); } sum += digit; } return sum % 10 == 0; } - int[] decodeEnd(BitArray row, int endStart) throws ReaderException { + int[] decodeEnd(BitArray row, int endStart) throws NotFoundException { return findGuardPattern(row, endStart, false, START_END_PATTERN); } @@ -228,10 +232,10 @@ public abstract class UPCEANReader extends OneDReader { * @param pattern pattern of counts of number of black and white pixels that are being * searched for as a pattern * @return start/end horizontal offset of guard pattern, as an array of two ints - * @throws ReaderException if pattern is not found + * @throws NotFoundException if pattern is not found */ static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern) - throws ReaderException { + throws NotFoundException { int patternLength = pattern.length; int[] counters = new int[patternLength]; int width = row.getSize(); @@ -269,7 +273,7 @@ public abstract class UPCEANReader extends OneDReader { isWhite = !isWhite; } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } /** @@ -282,10 +286,10 @@ public abstract class UPCEANReader extends OneDReader { * for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should * be used * @return horizontal offset of first pixel beyond the decoded digit - * @throws ReaderException if digit cannot be decoded + * @throws NotFoundException if digit cannot be decoded */ static int decodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns) - throws ReaderException { + throws NotFoundException { recordPattern(row, rowOffset, counters); int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; @@ -301,7 +305,7 @@ public abstract class UPCEANReader extends OneDReader { if (bestMatch >= 0) { return bestMatch; } else { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } } @@ -320,9 +324,9 @@ public abstract class UPCEANReader extends OneDReader { * @param startRange start/end offset of start guard pattern * @param resultString {@link StringBuffer} to append decoded chars to * @return horizontal offset of first pixel after the "middle" that was decoded - * @throws ReaderException if decoding could not complete successfully + * @throws NotFoundException if decoding could not complete successfully */ protected abstract int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString) - throws ReaderException; + throws NotFoundException; } diff --git a/core/src/com/google/zxing/oned/UPCEReader.java b/core/src/com/google/zxing/oned/UPCEReader.java index 3dd95a4b..ef74b970 100644 --- a/core/src/com/google/zxing/oned/UPCEReader.java +++ b/core/src/com/google/zxing/oned/UPCEReader.java @@ -17,7 +17,9 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitArray; /** @@ -53,7 +55,7 @@ public final class UPCEReader extends UPCEANReader { } protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result) - throws ReaderException { + throws NotFoundException { int[] counters = decodeMiddleCounters; counters[0] = 0; counters[1] = 0; @@ -80,16 +82,16 @@ public final class UPCEReader extends UPCEANReader { 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++) { @@ -100,7 +102,7 @@ public final class UPCEReader extends UPCEANReader { } } } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } BarcodeFormat getBarcodeFormat() { diff --git a/core/src/com/google/zxing/pdf417/PDF417Reader.java b/core/src/com/google/zxing/pdf417/PDF417Reader.java index fda7a4c2..1fcd1f12 100644 --- a/core/src/com/google/zxing/pdf417/PDF417Reader.java +++ b/core/src/com/google/zxing/pdf417/PDF417Reader.java @@ -19,8 +19,9 @@ package com.google.zxing.pdf417; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; -import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; @@ -46,14 +47,15 @@ public final class PDF417Reader implements Reader { * Locates and decodes a PDF417 code in an image. * * @return a String representing the content encoded by the PDF417 code - * @throws ReaderException if a PDF417 code cannot be found, or cannot be decoded + * @throws NotFoundException if a PDF417 code cannot be found, + * @throws FormatException if a PDF417 cannot be decoded */ - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) throws NotFoundException, FormatException { return decode(image, null); } public Result decode(BinaryBitmap image, Hashtable hints) - throws ReaderException { + throws NotFoundException, FormatException { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) { @@ -79,7 +81,7 @@ public final class PDF417Reader implements Reader { * around it. This is a specialized method that works exceptionally fast in this special * case. */ - private static BitMatrix extractPureBits(BinaryBitmap image) throws ReaderException { + private static BitMatrix extractPureBits(BinaryBitmap image) throws NotFoundException { // Now need to determine module size in pixels BitMatrix matrix = image.getBlackMatrix(); int height = matrix.getHeight(); @@ -92,7 +94,7 @@ public final class PDF417Reader implements Reader { borderWidth++; } if (borderWidth == minDimension) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // And then keep tracking across the top-left black module to determine module size @@ -101,7 +103,7 @@ public final class PDF417Reader implements Reader { moduleEnd++; } if (moduleEnd == minDimension) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int moduleSize = moduleEnd - borderWidth; @@ -112,13 +114,13 @@ public final class PDF417Reader implements Reader { rowEndOfSymbol--; } if (rowEndOfSymbol < 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } rowEndOfSymbol++; // Make sure width of barcode is a multiple of module size if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int dimension = (rowEndOfSymbol - borderWidth) / moduleSize; @@ -129,7 +131,7 @@ public final class PDF417Reader implements Reader { int sampleDimension = borderWidth + (dimension - 1) * moduleSize; if (sampleDimension >= width || sampleDimension >= height) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Now just read off the bits diff --git a/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java b/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java index ca85e2f2..03c12ac6 100644 --- a/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java +++ b/core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java @@ -16,7 +16,7 @@ package com.google.zxing.pdf417.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitMatrix; /** @@ -379,7 +379,7 @@ final class BitMatrixParser { * @param next the next available index into the codewords array. * @return the next available index into the codeword array after processing * this row. - * @throws ReaderException + * @throws NotFoundException */ /* int processRow1(int[] rowCounters, int rowNumber, int rowHeight, diff --git a/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java index a8cf5921..06388434 100644 --- a/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java @@ -16,7 +16,7 @@ package com.google.zxing.pdf417.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; import com.google.zxing.common.DecoderResult; /** @@ -81,7 +81,7 @@ final class DecodedBitStreamParser { private DecodedBitStreamParser() { } - static DecoderResult decode(int[] codewords) throws ReaderException { + static DecoderResult decode(int[] codewords) throws FormatException { StringBuffer result = new StringBuffer(100); // Get compaction mode int codeIndex = 1; @@ -120,7 +120,7 @@ final class DecodedBitStreamParser { if (codeIndex < codewords.length) { code = codewords[codeIndex++]; } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } return new DecoderResult(null, result.toString(), null, null); diff --git a/core/src/com/google/zxing/pdf417/decoder/Decoder.java b/core/src/com/google/zxing/pdf417/decoder/Decoder.java index fb722b68..1936c5af 100644 --- a/core/src/com/google/zxing/pdf417/decoder/Decoder.java +++ b/core/src/com/google/zxing/pdf417/decoder/Decoder.java @@ -16,7 +16,9 @@ package com.google.zxing.pdf417.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; //import com.google.zxing.pdf417.reedsolomon.ReedSolomonDecoder; @@ -44,9 +46,9 @@ public final class Decoder { * * @param image booleans representing white/black PDF417 modules * @return text and bytes encoded within the PDF417 Code - * @throws ReaderException if the PDF417 Code cannot be decoded + * @throws NotFoundException if the PDF417 Code cannot be decoded */ - public DecoderResult decode(boolean[][] image) throws ReaderException { + public DecoderResult decode(boolean[][] image) throws FormatException { int dimension = image.length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { @@ -65,14 +67,14 @@ public final class Decoder { * * @param bits booleans representing white/black PDF417 Code modules * @return text and bytes encoded within the PDF417 Code - * @throws ReaderException if the PDF417 Code cannot be decoded + * @throws FormatException if the PDF417 Code cannot be decoded */ - public DecoderResult decode(BitMatrix bits) throws ReaderException { + public DecoderResult decode(BitMatrix bits) throws FormatException { // Construct a parser to read the data codewords and error-correction level BitMatrixParser parser = new BitMatrixParser(bits); int[] codewords = parser.readCodewords(); if (codewords == null || codewords.length == 0) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } int ecLevel = parser.getECLevel(); @@ -91,27 +93,27 @@ public final class Decoder { * * @param codewords * @return an index to the first data codeword. - * @throws ReaderException + * @throws FormatException */ - private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws ReaderException { + private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws FormatException { if (codewords.length < 4) { // Codeword array size should be at least 4 allowing for // Count CW, At least one Data CW, Error Correction CW, Error Correction CW - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } // The first codeword, the Symbol Length Descriptor, shall always encode the total number of data // codewords in the symbol, including the Symbol Length Descriptor itself, data codewords and pad // codewords, but excluding the number of error correction codewords. int numberOfCodewords = codewords[0]; if (numberOfCodewords > codewords.length) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } if (numberOfCodewords == 0) { // Reset to the length of the array - 8 (Allow for at least level 3 Error Correction (8 Error Codewords) if (numECCodewords < codewords.length) { codewords[0] = codewords.length - numECCodewords; } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } } @@ -121,15 +123,16 @@ public final class Decoder { * correct the errors in-place using Reed-Solomon error correction.

* * @param codewords data and error correction codewords - * @throws ReaderException if error correction fails + * @throws ChecksumException if error correction fails */ - private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws ReaderException { + private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws FormatException { if ((erasures != null && erasures.length > numECCodewords / 2 + MAX_ERRORS) || (numECCodewords < 0 || numECCodewords > MAX_EC_CODEWORDS)) { // Too many errors or EC Codewords is corrupted - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } // Try to correct the errors + // TODO enable error correction int result = 0; // rsDecoder.correctErrors(codewords, numECCodewords); if (erasures != null) { int numErasures = erasures.length; @@ -138,7 +141,7 @@ public final class Decoder { } if (numErasures > MAX_ERRORS) { // Still too many errors - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } return result; diff --git a/core/src/com/google/zxing/pdf417/detector/Detector.java b/core/src/com/google/zxing/pdf417/detector/Detector.java index 6c448d8b..7b841fae 100644 --- a/core/src/com/google/zxing/pdf417/detector/Detector.java +++ b/core/src/com/google/zxing/pdf417/detector/Detector.java @@ -17,7 +17,7 @@ package com.google.zxing.pdf417.detector; import com.google.zxing.BinaryBitmap; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DetectorResult; @@ -62,9 +62,9 @@ public final class Detector { *

Detects a PDF417 Code in an image, simply.

* * @return {@link DetectorResult} encapsulating results of detecting a PDF417 Code - * @throws ReaderException if no QR Code can be found + * @throws NotFoundException if no QR Code can be found */ - public DetectorResult detect() throws ReaderException { + public DetectorResult detect() throws NotFoundException { return detect(null); } @@ -73,9 +73,9 @@ public final class Detector { * * @param hints optional hints to detector * @return {@link DetectorResult} encapsulating results of detecting a PDF417 Code - * @throws ReaderException if no PDF417 Code can be found + * @throws NotFoundException if no PDF417 Code can be found */ - public DetectorResult detect(Hashtable hints) throws ReaderException { + public DetectorResult detect(Hashtable hints) throws NotFoundException { // Fetch the 1 bit matrix once up front. BitMatrix matrix = image.getBlackMatrix(); @@ -91,26 +91,26 @@ public final class Detector { correctCodeWordVertices(vertices, false); } - if (vertices != null) { - float moduleWidth = computeModuleWidth(vertices); - if (moduleWidth < 1.0f) { - throw ReaderException.getInstance(); - } + if (vertices == null) { + throw NotFoundException.getNotFoundInstance(); + } - int dimension = computeDimension(vertices[4], vertices[6], - vertices[5], vertices[7], moduleWidth); - if (dimension < 1) { - throw ReaderException.getInstance(); - } + float moduleWidth = computeModuleWidth(vertices); + if (moduleWidth < 1.0f) { + throw NotFoundException.getNotFoundInstance(); + } - // Deskew and sample image. - BitMatrix bits = sampleGrid(matrix, vertices[4], vertices[5], - vertices[6], vertices[7], dimension); - return new DetectorResult(bits, new ResultPoint[]{vertices[4], - vertices[5], vertices[6], vertices[7]}); - } else { - throw ReaderException.getInstance(); + int dimension = computeDimension(vertices[4], vertices[6], + vertices[5], vertices[7], moduleWidth); + if (dimension < 1) { + throw NotFoundException.getNotFoundInstance(); } + + // Deskew and sample image. + BitMatrix bits = sampleGrid(matrix, vertices[4], vertices[5], + vertices[6], vertices[7], dimension); + return new DetectorResult(bits, new ResultPoint[]{vertices[4], + vertices[5], vertices[6], vertices[7]}); } /** @@ -374,7 +374,7 @@ public final class Detector { private static BitMatrix sampleGrid(BitMatrix matrix, ResultPoint topLeft, ResultPoint bottomLeft, ResultPoint topRight, ResultPoint bottomRight, int dimension) - throws ReaderException { + throws NotFoundException { // Note that unlike the QR Code sampler, we didn't find the center of modules, but the // very corners. So there is no 0.5f here; 0.0f is right. diff --git a/core/src/com/google/zxing/qrcode/QRCodeReader.java b/core/src/com/google/zxing/qrcode/QRCodeReader.java index 52002ae7..d9abc934 100644 --- a/core/src/com/google/zxing/qrcode/QRCodeReader.java +++ b/core/src/com/google/zxing/qrcode/QRCodeReader.java @@ -17,13 +17,15 @@ package com.google.zxing.qrcode; import com.google.zxing.BarcodeFormat; +import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; -import com.google.zxing.ReaderException; import com.google.zxing.Result; -import com.google.zxing.ResultPoint; import com.google.zxing.ResultMetadataType; -import com.google.zxing.BinaryBitmap; +import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.DetectorResult; @@ -51,14 +53,16 @@ public class QRCodeReader implements Reader { * Locates and decodes a QR code in an image. * * @return a String representing the content encoded by the QR code - * @throws ReaderException if a QR code cannot be found, or cannot be decoded + * @throws NotFoundException if a QR code cannot be found + * @throws FormatException if a QR code cannot be decoded + * @throws ChecksumException if error correction fails */ - public Result decode(BinaryBitmap image) throws ReaderException { + public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException { return decode(image, null); } public Result decode(BinaryBitmap image, Hashtable hints) - throws ReaderException { + throws NotFoundException, ChecksumException, FormatException { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) { @@ -91,7 +95,7 @@ public class QRCodeReader implements Reader { * around it. This is a specialized method that works exceptionally fast in this special * case. */ - private static BitMatrix extractPureBits(BitMatrix image) throws ReaderException { + private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException { // Now need to determine module size in pixels int height = image.getHeight(); @@ -104,7 +108,7 @@ public class QRCodeReader implements Reader { borderWidth++; } if (borderWidth == minDimension) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // And then keep tracking across the top-left black module to determine module size @@ -113,7 +117,7 @@ public class QRCodeReader implements Reader { moduleEnd++; } if (moduleEnd == minDimension) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int moduleSize = moduleEnd - borderWidth; @@ -124,13 +128,13 @@ public class QRCodeReader implements Reader { rowEndOfSymbol--; } if (rowEndOfSymbol < 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } rowEndOfSymbol++; // Make sure width of barcode is a multiple of module size if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int dimension = (rowEndOfSymbol - borderWidth) / moduleSize; @@ -141,7 +145,7 @@ public class QRCodeReader implements Reader { int sampleDimension = borderWidth + (dimension - 1) * moduleSize; if (sampleDimension >= width || sampleDimension >= height) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Now just read off the bits diff --git a/core/src/com/google/zxing/qrcode/QRCodeWriter.java b/core/src/com/google/zxing/qrcode/QRCodeWriter.java index 028aa8ed..7d516c61 100644 --- a/core/src/com/google/zxing/qrcode/QRCodeWriter.java +++ b/core/src/com/google/zxing/qrcode/QRCodeWriter.java @@ -21,9 +21,9 @@ import com.google.zxing.EncodeHintType; import com.google.zxing.Writer; import com.google.zxing.WriterException; import com.google.zxing.common.ByteMatrix; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.encoder.Encoder; import com.google.zxing.qrcode.encoder.QRCode; -import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import java.util.Hashtable; diff --git a/core/src/com/google/zxing/qrcode/decoder/BitMatrixParser.java b/core/src/com/google/zxing/qrcode/decoder/BitMatrixParser.java index fd8071c3..c6f79b3d 100644 --- a/core/src/com/google/zxing/qrcode/decoder/BitMatrixParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/BitMatrixParser.java @@ -16,7 +16,7 @@ package com.google.zxing.qrcode.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitMatrix; /** @@ -30,12 +30,12 @@ final class BitMatrixParser { /** * @param bitMatrix {@link BitMatrix} to parse - * @throws ReaderException if dimension is not >= 21 and 1 mod 4 + * @throws FormatException if dimension is not >= 21 and 1 mod 4 */ - BitMatrixParser(BitMatrix bitMatrix) throws ReaderException { + BitMatrixParser(BitMatrix bitMatrix) throws FormatException { int dimension = bitMatrix.getDimension(); if (dimension < 21 || (dimension & 0x03) != 1) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } this.bitMatrix = bitMatrix; } @@ -44,10 +44,10 @@ final class BitMatrixParser { *

Reads format information from one of its two locations within the QR Code.

* * @return {@link FormatInformation} encapsulating the QR Code's format info - * @throws ReaderException if both format information locations cannot be parsed as + * @throws FormatException if both format information locations cannot be parsed as * the valid encoding of format information */ - FormatInformation readFormatInformation() throws ReaderException { + FormatInformation readFormatInformation() throws FormatException { if (parsedFormatInfo != null) { return parsedFormatInfo; @@ -87,17 +87,17 @@ final class BitMatrixParser { if (parsedFormatInfo != null) { return parsedFormatInfo; } - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } /** *

Reads version information from one of its two locations within the QR Code.

* * @return {@link Version} encapsulating the QR Code's version - * @throws ReaderException if both version information locations cannot be parsed as + * @throws FormatException if both version information locations cannot be parsed as * the valid encoding of version information */ - Version readVersion() throws ReaderException { + Version readVersion() throws FormatException { if (parsedVersion != null) { return parsedVersion; @@ -136,7 +136,7 @@ final class BitMatrixParser { if (parsedVersion != null && parsedVersion.getDimensionForVersion() == dimension) { return parsedVersion; } - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } private int copyBit(int i, int j, int versionBits) { @@ -149,9 +149,9 @@ final class BitMatrixParser { * QR Code.

* * @return bytes encoded within the QR Code - * @throws ReaderException if the exact number of bytes expected is not read + * @throws FormatException if the exact number of bytes expected is not read */ - byte[] readCodewords() throws ReaderException { + byte[] readCodewords() throws FormatException { FormatInformation formatInfo = readFormatInformation(); Version version = readVersion(); @@ -200,7 +200,7 @@ final class BitMatrixParser { readingUp ^= true; // readingUp = !readingUp; // switch directions } if (resultOffset != version.getTotalCodewords()) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } return result; } diff --git a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index 55ff6363..25907e3b 100644 --- a/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -17,7 +17,7 @@ package com.google.zxing.qrcode.decoder; import com.google.zxing.DecodeHintType; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitSource; import com.google.zxing.common.CharacterSetECI; import com.google.zxing.common.DecoderResult; @@ -60,7 +60,7 @@ final class DecodedBitStreamParser { } static DecoderResult decode(byte[] bytes, Version version, ErrorCorrectionLevel ecLevel, Hashtable hints) - throws ReaderException { + throws FormatException { BitSource bits = new BitSource(bytes); StringBuffer result = new StringBuffer(50); CharacterSetECI currentCharacterSetECI = null; @@ -76,7 +76,7 @@ final class DecodedBitStreamParser { try { mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits } catch (IllegalArgumentException iae) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } if (!mode.equals(Mode.TERMINATOR)) { @@ -92,7 +92,7 @@ final class DecodedBitStreamParser { int value = parseECIValue(bits); currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value); if (currentCharacterSetECI == null) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } else { // How many characters will follow, encoded in this mode? @@ -106,7 +106,7 @@ final class DecodedBitStreamParser { } else if (mode.equals(Mode.KANJI)) { decodeKanjiSegment(bits, result, count); } else { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } } @@ -117,7 +117,7 @@ final class DecodedBitStreamParser { private static void decodeKanjiSegment(BitSource bits, StringBuffer result, - int count) throws ReaderException { + int count) throws FormatException { // Each character will require 2 bytes. Read the characters as 2-byte pairs // and decode as Shift_JIS afterwards byte[] buffer = new byte[2 * count]; @@ -142,7 +142,7 @@ final class DecodedBitStreamParser { try { result.append(new String(buffer, SHIFT_JIS)); } catch (UnsupportedEncodingException uee) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } @@ -151,10 +151,10 @@ final class DecodedBitStreamParser { int count, CharacterSetECI currentCharacterSetECI, Vector byteSegments, - Hashtable hints) throws ReaderException { + Hashtable hints) throws FormatException { byte[] readBytes = new byte[count]; if (count << 3 > bits.available()) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } for (int i = 0; i < count; i++) { readBytes[i] = (byte) bits.readBits(8); @@ -173,7 +173,7 @@ final class DecodedBitStreamParser { try { result.append(new String(readBytes, encoding)); } catch (UnsupportedEncodingException uce) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } byteSegments.addElement(readBytes); } @@ -213,13 +213,13 @@ final class DecodedBitStreamParser { private static void decodeNumericSegment(BitSource bits, StringBuffer result, - int count) throws ReaderException { + int count) throws FormatException { // Read three digits at a time while (count >= 3) { // Each 10 bits encodes three digits int threeDigitsBits = bits.readBits(10); if (threeDigitsBits >= 1000) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } result.append(ALPHANUMERIC_CHARS[threeDigitsBits / 100]); result.append(ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]); @@ -230,7 +230,7 @@ final class DecodedBitStreamParser { // Two digits left over to read, encoded in 7 bits int twoDigitsBits = bits.readBits(7); if (twoDigitsBits >= 100) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } result.append(ALPHANUMERIC_CHARS[twoDigitsBits / 10]); result.append(ALPHANUMERIC_CHARS[twoDigitsBits % 10]); @@ -238,7 +238,7 @@ final class DecodedBitStreamParser { // One digit left over to read int digitBits = bits.readBits(4); if (digitBits >= 10) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } result.append(ALPHANUMERIC_CHARS[digitBits]); } diff --git a/core/src/com/google/zxing/qrcode/decoder/Decoder.java b/core/src/com/google/zxing/qrcode/decoder/Decoder.java index 6a576f88..f7d52732 100644 --- a/core/src/com/google/zxing/qrcode/decoder/Decoder.java +++ b/core/src/com/google/zxing/qrcode/decoder/Decoder.java @@ -16,7 +16,9 @@ package com.google.zxing.qrcode.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.ChecksumException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import com.google.zxing.common.reedsolomon.GF256; @@ -39,7 +41,8 @@ public final class Decoder { rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD); } - public DecoderResult decode(boolean[][] image) throws ReaderException { + public DecoderResult decode(boolean[][] image) + throws ChecksumException, FormatException, NotFoundException { return decode(image, null); } @@ -49,9 +52,12 @@ public final class Decoder { * * @param image booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code - * @throws ReaderException if the QR Code cannot be decoded + * @throws NotFoundException if the QR Code cannot be found + * @throws FormatException if the QR Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(boolean[][] image, Hashtable hints) throws ReaderException { + public DecoderResult decode(boolean[][] image, Hashtable hints) + throws ChecksumException, FormatException, NotFoundException { int dimension = image.length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { @@ -64,7 +70,7 @@ public final class Decoder { return decode(bits, hints); } - public DecoderResult decode(BitMatrix bits) throws ReaderException { + public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException, NotFoundException { return decode(bits, null); } @@ -73,9 +79,12 @@ public final class Decoder { * * @param bits booleans representing white/black QR Code modules * @return text and bytes encoded within the QR Code - * @throws ReaderException if the QR Code cannot be decoded + * @throws NotFoundException if the QR Code cannot be found + * @throws FormatException if the QR Code cannot be decoded + * @throws ChecksumException if error correction fails */ - public DecoderResult decode(BitMatrix bits, Hashtable hints) throws ReaderException { + public DecoderResult decode(BitMatrix bits, Hashtable hints) + throws NotFoundException, FormatException, ChecksumException { // Construct a parser and read version, error-correction level BitMatrixParser parser = new BitMatrixParser(bits); @@ -116,9 +125,9 @@ public final class Decoder { * * @param codewordBytes data and error correction codewords * @param numDataCodewords number of codewords that are data bytes - * @throws ReaderException if error correction fails + * @throws ChecksumException if error correction fails */ - private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException { + 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]; @@ -129,7 +138,7 @@ public final class Decoder { try { rsDecoder.decode(codewordsInts, numECCodewords); } catch (ReedSolomonException rse) { - throw ReaderException.getInstance(); + 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 diff --git a/core/src/com/google/zxing/qrcode/decoder/Version.java b/core/src/com/google/zxing/qrcode/decoder/Version.java index 823bf2b7..497a63f7 100755 --- a/core/src/com/google/zxing/qrcode/decoder/Version.java +++ b/core/src/com/google/zxing/qrcode/decoder/Version.java @@ -16,7 +16,7 @@ package com.google.zxing.qrcode.decoder; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; import com.google.zxing.common.BitMatrix; /** @@ -91,16 +91,16 @@ public final class Version { * * @param dimension dimension in modules * @return {@link Version} for a QR Code of that dimension - * @throws ReaderException if dimension is not 1 mod 4 + * @throws FormatException if dimension is not 1 mod 4 */ - public static Version getProvisionalVersionForDimension(int dimension) throws ReaderException { + public static Version getProvisionalVersionForDimension(int dimension) throws FormatException { if (dimension % 4 != 1) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } try { return getVersionForNumber((dimension - 17) >> 2); } catch (IllegalArgumentException iae) { - throw ReaderException.getInstance(); + throw FormatException.getFormatInstance(); } } diff --git a/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java index 83a035d9..c85cd72e 100644 --- a/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java @@ -16,7 +16,7 @@ package com.google.zxing.qrcode.detector; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.ResultPointCallback; import com.google.zxing.common.BitMatrix; @@ -82,9 +82,9 @@ final class AlignmentPatternFinder { * it's pretty performance-critical and so is written to be fast foremost.

* * @return {@link AlignmentPattern} if found - * @throws ReaderException if not found + * @throws NotFoundException if not found */ - AlignmentPattern find() throws ReaderException { + AlignmentPattern find() throws NotFoundException { int startX = this.startX; int height = this.height; int maxJ = startX + width; @@ -150,7 +150,7 @@ final class AlignmentPatternFinder { return (AlignmentPattern) possibleCenters.elementAt(0); } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } /** diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index ae7d9f55..82d50a63 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -17,7 +17,8 @@ package com.google.zxing.qrcode.detector; import com.google.zxing.DecodeHintType; -import com.google.zxing.ReaderException; +import com.google.zxing.FormatException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.ResultPointCallback; import com.google.zxing.common.BitMatrix; @@ -55,9 +56,9 @@ public class Detector { *

Detects a QR Code in an image, simply.

* * @return {@link DetectorResult} encapsulating results of detecting a QR Code - * @throws ReaderException if no QR Code can be found + * @throws NotFoundException if no QR Code can be found */ - public DetectorResult detect() throws ReaderException { + public DetectorResult detect() throws NotFoundException, FormatException { return detect(null); } @@ -65,10 +66,11 @@ public class Detector { *

Detects a QR Code in an image, simply.

* * @param hints optional hints to detector - * @return {@link DetectorResult} encapsulating results of detecting a QR Code - * @throws ReaderException if no QR Code can be found + * @return {@link NotFoundException} encapsulating results of detecting a QR Code + * @throws NotFoundException if QR Code cannot be found + * @throws FormatException if a QR Code cannot be decoded */ - public DetectorResult detect(Hashtable hints) throws ReaderException { + public DetectorResult detect(Hashtable hints) throws NotFoundException, FormatException { resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); @@ -79,7 +81,8 @@ public class Detector { return processFinderPatternInfo(info); } - protected DetectorResult processFinderPatternInfo(FinderPatternInfo info) throws ReaderException { + protected DetectorResult processFinderPatternInfo(FinderPatternInfo info) + throws NotFoundException, FormatException { FinderPattern topLeft = info.getTopLeft(); FinderPattern topRight = info.getTopRight(); @@ -87,7 +90,7 @@ public class Detector { float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft); if (moduleSize < 1.0f) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize); Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension); @@ -115,7 +118,7 @@ public class Detector { estAlignmentY, (float) i); break; - } catch (ReaderException re) { + } catch (NotFoundException re) { // try next round } } @@ -180,7 +183,7 @@ public class Detector { private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, - int dimension) throws ReaderException { + int dimension) throws NotFoundException { GridSampler sampler = GridSampler.getInstance(); return sampler.sampleGrid(image, dimension, transform); @@ -193,7 +196,7 @@ public class Detector { protected static int computeDimension(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, - float moduleSize) throws ReaderException { + float moduleSize) throws NotFoundException { int tltrCentersDimension = round(ResultPoint.distance(topLeft, topRight) / moduleSize); int tlblCentersDimension = round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize); int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7; @@ -206,7 +209,7 @@ public class Detector { dimension--; break; case 3: - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } return dimension; } @@ -352,20 +355,20 @@ public class Detector { * @param estAlignmentY y coordinate of above * @param allowanceFactor number of pixels in all directions to search from the center * @return {@link AlignmentPattern} if found, or null otherwise - * @throws ReaderException if an unexpected error occurs during detection + * @throws NotFoundException if an unexpected error occurs during detection */ protected AlignmentPattern findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY, float allowanceFactor) - throws ReaderException { + throws NotFoundException { // Look for an alignment pattern (3 modules in size) around where it // should be int allowance = (int) (allowanceFactor * overallEstModuleSize); int alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance); int alignmentAreaRightX = Math.min(image.getWidth() - 1, estAlignmentX + allowance); if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) { - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } int alignmentAreaTopY = Math.max(0, estAlignmentY - allowance); diff --git a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java index 776f7263..6c388a82 100755 --- a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java @@ -17,12 +17,12 @@ package com.google.zxing.qrcode.detector; import com.google.zxing.DecodeHintType; -import com.google.zxing.ReaderException; +import com.google.zxing.NotFoundException; import com.google.zxing.ResultPoint; import com.google.zxing.ResultPointCallback; +import com.google.zxing.common.BitMatrix; import com.google.zxing.common.Collections; import com.google.zxing.common.Comparator; -import com.google.zxing.common.BitMatrix; import java.util.Hashtable; import java.util.Vector; @@ -72,7 +72,7 @@ public class FinderPatternFinder { return possibleCenters; } - FinderPatternInfo find(Hashtable hints) throws ReaderException { + FinderPatternInfo find(Hashtable hints) throws NotFoundException { boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); int maxI = image.getHeight(); int maxJ = image.getWidth(); @@ -488,14 +488,14 @@ public class FinderPatternFinder { * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are * those that have been detected at least {@link #CENTER_QUORUM} times, and whose module * size differs from the average among those patterns the least - * @throws ReaderException if 3 such finder patterns do not exist + * @throws NotFoundException if 3 such finder patterns do not exist */ - private FinderPattern[] selectBestPatterns() throws ReaderException { + private FinderPattern[] selectBestPatterns() throws NotFoundException { int startSize = possibleCenters.size(); if (startSize < 3) { // Couldn't find enough finder patterns - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); } // Filter outlier possibilities whose module size is too different diff --git a/core/src/com/google/zxing/qrcode/encoder/Encoder.java b/core/src/com/google/zxing/qrcode/encoder/Encoder.java index 55c1bcae..fd02c3ba 100644 --- a/core/src/com/google/zxing/qrcode/encoder/Encoder.java +++ b/core/src/com/google/zxing/qrcode/encoder/Encoder.java @@ -16,8 +16,8 @@ package com.google.zxing.qrcode.encoder; -import com.google.zxing.WriterException; import com.google.zxing.EncodeHintType; +import com.google.zxing.WriterException; import com.google.zxing.common.ByteArray; import com.google.zxing.common.ByteMatrix; import com.google.zxing.common.CharacterSetECI; @@ -27,9 +27,9 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.Mode; import com.google.zxing.qrcode.decoder.Version; -import java.util.Vector; -import java.util.Hashtable; import java.io.UnsupportedEncodingException; +import java.util.Hashtable; +import java.util.Vector; /** * @author satorux@google.com (Satoru Takabayashi) - creator diff --git a/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java index 9c2ecaaf..68548440 100644 --- a/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; import java.util.Arrays; diff --git a/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java index d44c3408..08bf2c5c 100644 --- a/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link CalendarParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java index 152d1c0b..c3fc5fdf 100644 --- a/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link EmailAddressParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java index 292da837..f10820e5 100644 --- a/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link com.google.zxing.client.result.GeoParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java index 8a258490..4f3b9667 100644 --- a/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link ISBNParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java index 36a95cde..d1f53d2e 100644 --- a/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link ProductParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java index 663bfa43..6dc28481 100644 --- a/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link SMSParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java index 9e110989..7d754fed 100644 --- a/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link TelParsedResult}. diff --git a/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java b/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java index d35cec2e..055f86c3 100644 --- a/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java @@ -16,9 +16,9 @@ package com.google.zxing.client.result; -import junit.framework.TestCase; -import com.google.zxing.Result; import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import junit.framework.TestCase; /** * Tests {@link URIParsedResult}. diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index 2ef12b43..d078fa12 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -24,9 +24,9 @@ import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; - import junit.framework.TestCase; +import javax.imageio.ImageIO; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; @@ -41,8 +41,6 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; -import javax.imageio.ImageIO; - /** * @author Sean Owen * @author dswitkin@google.com (Daniel Switkin) diff --git a/core/test/src/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java index 88f82497..74fdda81 100644 --- a/core/test/src/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java @@ -23,14 +23,13 @@ import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; +import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.imageio.ImageIO; - /** * This abstract class looks for negative results, i.e. it only allows a certain number of false * positives in images which should not decode. This helps ensure that we are not too lenient. diff --git a/core/test/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParserTestCase.java b/core/test/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParserTestCase.java index 9d215f9b..9dc09783 100644 --- a/core/test/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParserTestCase.java +++ b/core/test/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParserTestCase.java @@ -18,14 +18,12 @@ package com.google.zxing.datamatrix.decoder; import junit.framework.TestCase; -import com.google.zxing.ReaderException; - /** * @author bbrown@google.com (Brian Brown) */ public final class DecodedBitStreamParserTestCase extends TestCase{ - public void testAsciiStandardDecode() throws ReaderException { + public void testAsciiStandardDecode() throws Exception { // ASCII characters 0-127 are encoded as the value + 1 byte[] bytes = {(byte) ('a' + 1), (byte) ('b' + 1), (byte) ('c' + 1), (byte) ('A' + 1), (byte) ('B' + 1), (byte) ('C' + 1)}; @@ -33,7 +31,7 @@ public final class DecodedBitStreamParserTestCase extends TestCase{ assertEquals("abcABC", decodedString); } - public void testAsciiDoubleDigitDecode() throws ReaderException{ + public void testAsciiDoubleDigitDecode() throws Exception{ // ASCII double digit (00 - 99) Numeric Value + 130 byte[] bytes = {(byte) 130 , (byte) ( 1 + 130), (byte) (98 + 130), (byte) (99 + 130)}; diff --git a/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java index 819031a0..1e154545 100644 --- a/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java b/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java index 1eeb1cfe..d3bc6dc1 100644 --- a/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java index 5478d98f..c0c4babb 100644 --- a/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.common.AbstractBlackBoxTestCase; import com.google.zxing.BarcodeFormat; +import com.google.zxing.common.AbstractBlackBoxTestCase; /** * @author Sean Owen diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java index 3a88d670..d3f9e6fd 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java index b3429a91..f79a97be 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/EAN13BlackBox3TestCase.java b/core/test/src/com/google/zxing/oned/EAN13BlackBox3TestCase.java index 607e0c8d..00700311 100644 --- a/core/test/src/com/google/zxing/oned/EAN13BlackBox3TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN13BlackBox3TestCase.java @@ -16,12 +16,10 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; -import java.io.File; - /** * @author dswitkin@google.com (Daniel Switkin) */ diff --git a/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java index bd0ac2a5..2515f55f 100644 --- a/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java index cddb2d94..285aa22d 100644 --- a/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java index f17ec520..8adccd73 100644 --- a/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCABlackBox3ReflectiveTestCase.java b/core/test/src/com/google/zxing/oned/UPCABlackBox3ReflectiveTestCase.java index e4cd667c..b1c4dbc4 100644 --- a/core/test/src/com/google/zxing/oned/UPCABlackBox3ReflectiveTestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCABlackBox3ReflectiveTestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java b/core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java index 316bd021..d18eab63 100644 --- a/core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java index b005ffd0..4e6c4c5f 100644 --- a/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCEBlackBox2TestCase.java b/core/test/src/com/google/zxing/oned/UPCEBlackBox2TestCase.java index cab69b76..885402af 100644 --- a/core/test/src/com/google/zxing/oned/UPCEBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCEBlackBox2TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/oned/UPCEBlackBox3ReflectiveTestCase.java b/core/test/src/com/google/zxing/oned/UPCEBlackBox3ReflectiveTestCase.java index ff5e1290..0cc9b4a5 100644 --- a/core/test/src/com/google/zxing/oned/UPCEBlackBox3ReflectiveTestCase.java +++ b/core/test/src/com/google/zxing/oned/UPCEBlackBox3ReflectiveTestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java index b0e16458..e789ce97 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.qrcode; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java index a5bac913..b31caa4e 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.qrcode; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java index 2901ac1e..bcdba726 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.qrcode; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox4TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox4TestCase.java index 49db0c92..3ef4ae6f 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox4TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox4TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.qrcode; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox5TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox5TestCase.java index 8fca08ef..a2cefddb 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox5TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox5TestCase.java @@ -16,8 +16,8 @@ package com.google.zxing.qrcode; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; /** diff --git a/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java b/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java index 8078b070..ddd1052e 100644 --- a/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java @@ -16,7 +16,6 @@ package com.google.zxing.qrcode.decoder; -import com.google.zxing.ReaderException; import com.google.zxing.common.BitSourceBuilder; import junit.framework.TestCase; @@ -27,7 +26,7 @@ import junit.framework.TestCase; */ public final class DecodedBitStreamParserTestCase extends TestCase { - public void testSimpleByteMode() throws ReaderException { + public void testSimpleByteMode() throws Exception { BitSourceBuilder builder = new BitSourceBuilder(); builder.write(0x04, 4); // Byte mode builder.write(0x03, 8); // 3 bytes @@ -39,7 +38,7 @@ public final class DecodedBitStreamParserTestCase extends TestCase { assertEquals("\u00f1\u00f2\u00f3", result); } - public void testSimpleSJIS() throws ReaderException { + public void testSimpleSJIS() throws Exception { BitSourceBuilder builder = new BitSourceBuilder(); builder.write(0x04, 4); // Byte mode builder.write(0x03, 8); // 3 bytes @@ -51,7 +50,7 @@ public final class DecodedBitStreamParserTestCase extends TestCase { assertEquals("\uff61\uff62\uff63", result); } - public void testECI() throws ReaderException { + public void testECI() throws Exception { BitSourceBuilder builder = new BitSourceBuilder(); builder.write(0x07, 4); // ECI mode builder.write(0x02, 8); // ECI 2 = CP437 encoding diff --git a/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java b/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java index c92d872c..64c5d4ee 100644 --- a/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java +++ b/core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java @@ -16,7 +16,6 @@ package com.google.zxing.qrcode.decoder; -import com.google.zxing.ReaderException; import junit.framework.TestCase; /** @@ -51,7 +50,7 @@ public final class VersionTestCase extends TestCase { assertNotNull(version.buildFunctionPattern()); } - public void testGetProvisionalVersionForDimension() throws ReaderException { + public void testGetProvisionalVersionForDimension() throws Exception { for (int i = 1; i <= 40; i++) { assertEquals(i, Version.getProvisionalVersionForDimension(4*i + 17).getVersionNumber()); } diff --git a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java index a7ad9d62..61ca47a9 100644 --- a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java +++ b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java @@ -18,9 +18,12 @@ package com.google.zxing.client.j2se; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; +import com.google.zxing.NotFoundException; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.client.result.ParsedResult; @@ -210,7 +213,7 @@ public final class CommandLineRunner { ", type: " + parsedResult.getType() + "):\nRaw result:\n" + result.getText() + "\nParsed result:\n" + parsedResult.getDisplayResult()); return result; - } catch (ReaderException e) { + } catch (NotFoundException nfe) { System.out.println(uri.toString() + ": No barcode found"); return null; } finally { @@ -247,7 +250,7 @@ public final class CommandLineRunner { for (int y = 0; y < height; y++) { try { row = bitmap.getBlackRow(y, row); - } catch (ReaderException e) { + } catch (NotFoundException nfe) { // If fetching the row failed, draw a red line and keep going. int offset = y * stride + width; for (int x = 0; x < width; x++) { @@ -279,7 +282,7 @@ public final class CommandLineRunner { } } } - } catch (ReaderException e) { + } catch (NotFoundException nfe) { } // Write the result diff --git a/javase/src/com/google/zxing/client/j2se/ImageConverter.java b/javase/src/com/google/zxing/client/j2se/ImageConverter.java index 538e59a0..2cbd5fef 100644 --- a/javase/src/com/google/zxing/client/j2se/ImageConverter.java +++ b/javase/src/com/google/zxing/client/j2se/ImageConverter.java @@ -18,6 +18,7 @@ package com.google.zxing.client.j2se; import com.google.zxing.BinaryBitmap; import com.google.zxing.LuminanceSource; +import com.google.zxing.NotFoundException; import com.google.zxing.ReaderException; import com.google.zxing.common.BitArray; import com.google.zxing.common.BitMatrix; @@ -107,7 +108,7 @@ public final class ImageConverter { for (int y = 0; y < height; y++) { try { array = bitmap.getBlackRow(y, array); - } catch (ReaderException e) { + } catch (NotFoundException nfe) { // Draw rows with insufficient dynamic range in red for (int x = 0; x < width; x++) { result.setRGB(x, y, RED); @@ -127,7 +128,7 @@ public final class ImageConverter { result.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE); } } - } catch (ReaderException e) { + } catch (NotFoundException nfe) { } } diff --git a/zxingorg/src/com/google/zxing/web/DecodeServlet.java b/zxingorg/src/com/google/zxing/web/DecodeServlet.java index adeedd80..3926f0f8 100644 --- a/zxingorg/src/com/google/zxing/web/DecodeServlet.java +++ b/zxingorg/src/com/google/zxing/web/DecodeServlet.java @@ -18,9 +18,12 @@ package com.google.zxing.web; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; +import com.google.zxing.ChecksumException; import com.google.zxing.DecodeHintType; +import com.google.zxing.FormatException; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; +import com.google.zxing.NotFoundException; import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; @@ -85,7 +88,7 @@ import javax.servlet.http.HttpServletResponse; */ public final class DecodeServlet extends HttpServlet { - private static final long MAX_IMAGE_SIZE = 500000L; + private static final long MAX_IMAGE_SIZE = 2000000L; private static final Logger log = Logger.getLogger(DecodeServlet.class.getName()); @@ -260,10 +263,18 @@ public final class DecodeServlet extends HttpServlet { LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = reader.decode(bitmap, HINTS); - } catch (ReaderException re2) { - log.info("DECODE FAILED: " + re.toString()); + } catch (NotFoundException nfe) { + log.info("Not found: " + re.toString()); response.sendRedirect("notfound.jspx"); return; + } catch (FormatException fe) { + log.info("Format problem: " + re.toString()); + response.sendRedirect("format.jspx"); + return; + } catch (ChecksumException ce) { + log.info("Checksum problem: " + re.toString()); + response.sendRedirect("format.jspx"); + return; } } diff --git a/zxingorg/web/format.jspx b/zxingorg/web/format.jspx new file mode 100644 index 00000000..a88ff9bd --- /dev/null +++ b/zxingorg/web/format.jspx @@ -0,0 +1,36 @@ + + + + + +response.setHeader("Cache-Control", "public"); +]]> + + + No Barcode Found + + + + +

A barcode was possibly found in this image, but a problem occurred while decoding it. The data did not conform + to the barcode format. This could be due to a misdetection of the barcode, or could indicate a problem + with the barcode contents. Go "Back" in your browser and try another image. +

+ + + +
-- 2.20.1