"Split" ReaderException into subclasses to enable more useful error reporting
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 2 Feb 2010 08:23:46 +0000 (08:23 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 2 Feb 2010 08:23:46 +0000 (08:23 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1195 59b500cc-1b3d-0410-9834-0bbf25fbcc57

88 files changed:
core/src/com/google/zxing/Binarizer.java
core/src/com/google/zxing/BinaryBitmap.java
core/src/com/google/zxing/ChecksumException.java [new file with mode: 0644]
core/src/com/google/zxing/FormatException.java [new file with mode: 0644]
core/src/com/google/zxing/MultiFormatReader.java
core/src/com/google/zxing/NotFoundException.java [new file with mode: 0644]
core/src/com/google/zxing/Reader.java
core/src/com/google/zxing/ReaderException.java
core/src/com/google/zxing/common/DefaultGridSampler.java
core/src/com/google/zxing/common/GlobalHistogramBinarizer.java
core/src/com/google/zxing/common/GridSampler.java
core/src/com/google/zxing/common/HybridBinarizer.java
core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java
core/src/com/google/zxing/datamatrix/DataMatrixReader.java
core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java
core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java
core/src/com/google/zxing/datamatrix/decoder/Decoder.java
core/src/com/google/zxing/datamatrix/decoder/Version.java
core/src/com/google/zxing/datamatrix/detector/Detector.java
core/src/com/google/zxing/multi/ByQuadrantReader.java
core/src/com/google/zxing/multi/GenericMultipleBarcodeReader.java
core/src/com/google/zxing/multi/MultipleBarcodeReader.java
core/src/com/google/zxing/multi/qrcode/QRCodeMultiReader.java
core/src/com/google/zxing/multi/qrcode/detector/MultiDetector.java
core/src/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java
core/src/com/google/zxing/oned/Code128Reader.java
core/src/com/google/zxing/oned/Code39Reader.java
core/src/com/google/zxing/oned/EAN13Reader.java
core/src/com/google/zxing/oned/EAN8Reader.java
core/src/com/google/zxing/oned/ITFReader.java
core/src/com/google/zxing/oned/MultiFormatOneDReader.java
core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java
core/src/com/google/zxing/oned/OneDReader.java
core/src/com/google/zxing/oned/UPCAReader.java
core/src/com/google/zxing/oned/UPCEANReader.java
core/src/com/google/zxing/oned/UPCEReader.java
core/src/com/google/zxing/pdf417/PDF417Reader.java
core/src/com/google/zxing/pdf417/decoder/BitMatrixParser.java
core/src/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java
core/src/com/google/zxing/pdf417/decoder/Decoder.java
core/src/com/google/zxing/pdf417/detector/Detector.java
core/src/com/google/zxing/qrcode/QRCodeReader.java
core/src/com/google/zxing/qrcode/QRCodeWriter.java
core/src/com/google/zxing/qrcode/decoder/BitMatrixParser.java
core/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java
core/src/com/google/zxing/qrcode/decoder/Decoder.java
core/src/com/google/zxing/qrcode/decoder/Version.java
core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java
core/src/com/google/zxing/qrcode/detector/Detector.java
core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java
core/src/com/google/zxing/qrcode/encoder/Encoder.java
core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/CalendarParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/EmailAddressParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/GeoParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/ISBNParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/ProductParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/SMSMMSParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/TelParsedResultTestCase.java
core/test/src/com/google/zxing/client/result/URIParsedResultTestCase.java
core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java
core/test/src/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java
core/test/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParserTestCase.java
core/test/src/com/google/zxing/oned/Code39BlackBox1TestCase.java
core/test/src/com/google/zxing/oned/Code39BlackBox3TestCase.java
core/test/src/com/google/zxing/oned/Code39ExtendedBlackBox2TestCase.java
core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java
core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java
core/test/src/com/google/zxing/oned/EAN13BlackBox3TestCase.java
core/test/src/com/google/zxing/oned/EAN8BlackBox1TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox2TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox3ReflectiveTestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java
core/test/src/com/google/zxing/oned/UPCEBlackBox1TestCase.java
core/test/src/com/google/zxing/oned/UPCEBlackBox2TestCase.java
core/test/src/com/google/zxing/oned/UPCEBlackBox3ReflectiveTestCase.java
core/test/src/com/google/zxing/qrcode/QRCodeBlackBox1TestCase.java
core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java
core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java
core/test/src/com/google/zxing/qrcode/QRCodeBlackBox4TestCase.java
core/test/src/com/google/zxing/qrcode/QRCodeBlackBox5TestCase.java
core/test/src/com/google/zxing/qrcode/decoder/DecodedBitStreamParserTestCase.java
core/test/src/com/google/zxing/qrcode/decoder/VersionTestCase.java
javase/src/com/google/zxing/client/j2se/CommandLineRunner.java
javase/src/com/google/zxing/client/j2se/ImageConverter.java
zxingorg/src/com/google/zxing/web/DecodeServlet.java
zxingorg/web/format.jspx [new file with mode: 0644]

index 4fd83b5..912a3b5 100644 (file)
@@ -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
index 377a54b..b97e467 100644 (file)
@@ -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 (file)
index 0000000..dedb4be
--- /dev/null
@@ -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 (file)
index 0000000..6967e93
--- /dev/null
@@ -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
index 499ff74..6685882 100644 (file)
 
 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 (file)
index 0000000..dedab8d
--- /dev/null
@@ -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
index cb74592..47e843b 100644 (file)
@@ -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
index 4e6a90f..224a497 100644 (file)
@@ -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<String,Integer> throwers = new HashMap<String,Integer>(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;
   }
 
index f0a9e07..9a2a683 100644 (file)
@@ -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;
index 015dfa9..144c099 100644 (file)
@@ -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.
index 5f2588f..84024be 100644 (file)
@@ -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) {
index d868148..e6a6952 100644 (file)
@@ -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) {
index 75eab7a..950a223 100644 (file)
@@ -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();
   }
 
   /**
index 30c2074..0154917 100644 (file)
 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
index 6536ebf..849f5be 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.datamatrix.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
 import com.google.zxing.common.BitMatrix;\r
 \r
 /**\r
@@ -30,12 +30,12 @@ final class BitMatrixParser {
 \r
   /**\r
    * @param bitMatrix {@link BitMatrix} to parse\r
-   * @throws ReaderException if dimension is < 10 or > 144 or not 0 mod 2\r
+   * @throws FormatException if dimension is < 10 or > 144 or not 0 mod 2\r
    */\r
-  BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {\r
+  BitMatrixParser(BitMatrix bitMatrix) throws FormatException {\r
     int dimension = bitMatrix.getDimension();\r
     if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     \r
     version = readVersion(bitMatrix);\r
@@ -52,10 +52,10 @@ final class BitMatrixParser {
    * \r
    * @param bitMatrix Original {@link BitMatrix} including alignment patterns\r
    * @return {@link Version} encapsulating the Data Matrix Code's "version"\r
-   * @throws ReaderException if the dimensions of the mapping matrix are not valid\r
+   * @throws FormatException if the dimensions of the mapping matrix are not valid\r
    * Data Matrix dimensions.\r
    */\r
-  Version readVersion(BitMatrix bitMatrix) throws ReaderException {\r
+  Version readVersion(BitMatrix bitMatrix) throws FormatException {\r
 \r
     if (version != null) {\r
       return version;\r
@@ -74,9 +74,9 @@ final class BitMatrixParser {
    * Data Matrix Code.</p>\r
    *\r
    * @return bytes encoded within the Data Matrix Code\r
-   * @throws ReaderException if the exact number of bytes expected is not read\r
+   * @throws FormatException if the exact number of bytes expected is not read\r
    */\r
-  byte[] readCodewords() throws ReaderException {\r
+  byte[] readCodewords() throws FormatException {\r
 \r
     byte[] result = new byte[version.getTotalCodewords()];\r
     int resultOffset = 0;\r
@@ -141,7 +141,7 @@ final class BitMatrixParser {
     } while ((row < numRows) || (column < numColumns));\r
 \r
     if (resultOffset != version.getTotalCodewords()) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     return result;\r
   }\r
index 7f6deca..d842f9c 100644 (file)
 
 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;
 
 /**
  * <p>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);
index 5b1e5db..58f8c98 100644 (file)
@@ -16,7 +16,8 @@
 \r
 package com.google.zxing.datamatrix.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
 import com.google.zxing.common.BitMatrix;\r
 import com.google.zxing.common.DecoderResult;\r
 import com.google.zxing.common.reedsolomon.GF256;\r
@@ -43,9 +44,10 @@ public final class Decoder {
    *\r
    * @param image booleans representing white/black Data Matrix Code modules\r
    * @return text and bytes encoded within the Data Matrix Code\r
-   * @throws ReaderException if the Data Matrix Code cannot be decoded\r
+   * @throws FormatException if the Data Matrix Code cannot be decoded\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+  public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException {\r
     int dimension = image.length;\r
     BitMatrix bits = new BitMatrix(dimension);\r
     for (int i = 0; i < dimension; i++) {\r
@@ -64,9 +66,10 @@ public final class Decoder {
    *\r
    * @param bits booleans representing white/black Data Matrix Code modules\r
    * @return text and bytes encoded within the Data Matrix Code\r
-   * @throws ReaderException if the Data Matrix Code cannot be decoded\r
+   * @throws FormatException if the Data Matrix Code cannot be decoded\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+  public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException {\r
 \r
     // Construct a parser and read version, error-correction level\r
     BitMatrixParser parser = new BitMatrixParser(bits);\r
@@ -106,9 +109,9 @@ public final class Decoder {
    *\r
    * @param codewordBytes data and error correction codewords\r
    * @param numDataCodewords number of codewords that are data bytes\r
-   * @throws ReaderException if error correction fails\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException {\r
+  private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {\r
     int numCodewords = codewordBytes.length;\r
     // First read into an array of ints\r
     int[] codewordsInts = new int[numCodewords];\r
@@ -119,7 +122,7 @@ public final class Decoder {
     try {\r
       rsDecoder.decode(codewordsInts, numECCodewords);\r
     } catch (ReedSolomonException rse) {\r
-      throw ReaderException.getInstance();\r
+      throw ChecksumException.getChecksumInstance();\r
     }\r
     // Copy back into array of bytes -- only need to worry about the bytes that were data\r
     // We don't care about errors in the error-correction codewords\r
index 2a941d1..d2b712b 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.datamatrix.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
 \r
 /**\r
  * The Version object encapsulates attributes about a particular\r
@@ -94,11 +94,11 @@ public final class Version {
    * @param numRows Number of rows in modules\r
    * @param numColumns Number of columns in modules\r
    * @return {@link Version} for a Data Matrix Code of those dimensions\r
-   * @throws ReaderException if dimensions do correspond to a valid Data Matrix size\r
+   * @throws FormatException if dimensions do correspond to a valid Data Matrix size\r
    */\r
-  public static Version getVersionForDimensions(int numRows, int numColumns) throws ReaderException {\r
+  public static Version getVersionForDimensions(int numRows, int numColumns) throws FormatException {\r
     if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     \r
     // TODO(bbrown): This is doing a linear search through the array of versions.\r
@@ -112,7 +112,7 @@ public final class Version {
       }\r
     }\r
     \r
-    throw ReaderException.getInstance();\r
+    throw FormatException.getFormatInstance();\r
   }\r
 \r
   /**\r
index 823c624..5915865 100644 (file)
@@ -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 {
    * <p>Detects a Data Matrix Code in an image.</p>
    *
    * @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
index aaf1afb..35904d3 100644 (file)
 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
     }
 
index 8760528..a6ace11 100644 (file)
 
 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];
index c3b4310..5f0c7eb 100644 (file)
@@ -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;
 
 }
index 191a714..72a7d68 100644 (file)
@@ -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++) {
index 8ce4d43..d3797d9 100644 (file)
 
 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
       }
     }
index d133400..0eb8ea1 100644 (file)
 package com.google.zxing.multi.qrcode.detector;\r
 \r
 import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.ResultPoint;\r
 import com.google.zxing.ResultPointCallback;\r
+import com.google.zxing.common.BitMatrix;\r
 import com.google.zxing.common.Collections;\r
 import com.google.zxing.common.Comparator;\r
-import com.google.zxing.common.BitMatrix;\r
 import com.google.zxing.qrcode.detector.FinderPattern;\r
 import com.google.zxing.qrcode.detector.FinderPatternFinder;\r
 import com.google.zxing.qrcode.detector.FinderPatternInfo;\r
@@ -99,15 +99,15 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
    * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are\r
    *         those that have been detected at least {@link #CENTER_QUORUM} times, and whose module\r
    *         size differs from the average among those patterns the least\r
-   * @throws ReaderException if 3 such finder patterns do not exist\r
+   * @throws NotFoundException if 3 such finder patterns do not exist\r
    */\r
-  private FinderPattern[][] selectBestPatterns() throws ReaderException {\r
+  private FinderPattern[][] selectBestPatterns() throws NotFoundException {\r
     Vector possibleCenters = getPossibleCenters();\r
     int size = possibleCenters.size();\r
 \r
     if (size < 3) {\r
       // Couldn't find enough finder patterns\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
 \r
     /*\r
@@ -227,10 +227,10 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
     }\r
 \r
     // Nothing found!\r
-    throw ReaderException.getInstance();\r
+    throw NotFoundException.getNotFoundInstance();\r
   }\r
 \r
-  public FinderPatternInfo[] findMulti(Hashtable hints) throws ReaderException {\r
+  public FinderPatternInfo[] findMulti(Hashtable hints) throws NotFoundException {\r
     boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);\r
     BitMatrix image = getImage();\r
     int maxI = image.getHeight();\r
index 981835b..e87bd71 100644 (file)
@@ -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;
index 36b7446..c997ec6 100644 (file)
@@ -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;
         }
index 67d82a8..9c90e83 100644 (file)
@@ -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();
   }
 
 }
index 3e64ea6..30fbacb 100644 (file)
@@ -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;
index 93c82dd..9a0a941 100644 (file)
@@ -18,7 +18,8 @@ package com.google.zxing.oned;
 \r
 import com.google.zxing.BarcodeFormat;\r
 import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.Result;\r
 import com.google.zxing.ResultPoint;\r
 import com.google.zxing.common.BitArray;\r
@@ -75,7 +76,7 @@ public final class ITFReader extends OneDReader {
       {N, W, N, W, N}  // 9\r
   };\r
 \r
-  public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException {\r
+  public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws FormatException, NotFoundException {\r
 \r
     // Find out where the Middle section (payload) starts & ends\r
     int[] startRange = decodeStart(row);\r
@@ -106,7 +107,7 @@ public final class ITFReader extends OneDReader {
 \r
     }\r
     if (!lengthOK) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
 \r
     return new Result(\r
@@ -121,10 +122,10 @@ public final class ITFReader extends OneDReader {
    * @param row          row of black/white values to search\r
    * @param payloadStart offset of start pattern\r
    * @param resultString {@link StringBuffer} to append decoded chars to\r
-   * @throws ReaderException if decoding could not complete successfully\r
+   * @throws NotFoundException if decoding could not complete successfully\r
    */\r
   private static void decodeMiddle(BitArray row, int payloadStart, int payloadEnd,\r
-      StringBuffer resultString) throws ReaderException {\r
+      StringBuffer resultString) throws NotFoundException {\r
 \r
     // Digits are interleaved in pairs - 5 black lines for one digit, and the\r
     // 5\r
@@ -163,9 +164,9 @@ public final class ITFReader extends OneDReader {
    * @param row row of black/white values to search\r
    * @return Array, containing index of start of 'start block' and end of\r
    *         'start block'\r
-   * @throws ReaderException\r
+   * @throws NotFoundException\r
    */\r
-  int[] decodeStart(BitArray row) throws ReaderException {\r
+  int[] decodeStart(BitArray row) throws NotFoundException {\r
     int endStart = skipWhiteSpace(row);\r
     int[] startPattern = findGuardPattern(row, endStart, START_PATTERN);\r
 \r
@@ -192,9 +193,9 @@ public final class ITFReader extends OneDReader {
    *\r
    * @param row bit array representing the scanned barcode.\r
    * @param startPattern index into row of the start or end pattern.\r
-   * @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown.\r
+   * @throws NotFoundException if the quiet zone cannot be found, a ReaderException is thrown.\r
    */\r
-  private void validateQuietZone(BitArray row, int startPattern) throws ReaderException {\r
+  private void validateQuietZone(BitArray row, int startPattern) throws NotFoundException {\r
 \r
     int quietCount = this.narrowLineWidth * 10;  // expect to find this many pixels of quiet zone\r
 \r
@@ -206,7 +207,7 @@ public final class ITFReader extends OneDReader {
     }\r
     if (quietCount != 0) {\r
       // Unable to find the necessary number of quiet zone pixels.\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
   }\r
 \r
@@ -215,9 +216,9 @@ public final class ITFReader extends OneDReader {
    *\r
    * @param row row of black/white values to search\r
    * @return index of the first black line.\r
-   * @throws ReaderException Throws exception if no black lines are found in the row\r
+   * @throws NotFoundException Throws exception if no black lines are found in the row\r
    */\r
-  private static int skipWhiteSpace(BitArray row) throws ReaderException {\r
+  private static int skipWhiteSpace(BitArray row) throws NotFoundException {\r
     int width = row.getSize();\r
     int endStart = 0;\r
     while (endStart < width) {\r
@@ -227,7 +228,7 @@ public final class ITFReader extends OneDReader {
       endStart++;\r
     }\r
     if (endStart == width) {\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
 \r
     return endStart;\r
@@ -239,10 +240,10 @@ public final class ITFReader extends OneDReader {
    * @param row row of black/white values to search\r
    * @return Array, containing index of start of 'end block' and end of 'end\r
    *         block'\r
-   * @throws ReaderException\r
+   * @throws NotFoundException\r
    */\r
 \r
-  int[] decodeEnd(BitArray row) throws ReaderException {\r
+  int[] decodeEnd(BitArray row) throws NotFoundException {\r
 \r
     // For convenience, reverse the row and then\r
     // search from 'the start' for the end block\r
@@ -277,9 +278,9 @@ public final class ITFReader extends OneDReader {
    *                  being searched for as a pattern\r
    * @return start/end horizontal offset of guard pattern, as an array of two\r
    *         ints\r
-   * @throws ReaderException if pattern is not found\r
+   * @throws NotFoundException if pattern is not found\r
    */\r
-  private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException {\r
+  private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws NotFoundException {\r
 \r
     // TODO: This is very similar to implementation in UPCEANReader. Consider if they can be\r
     // merged to a single method.\r
@@ -313,7 +314,7 @@ public final class ITFReader extends OneDReader {
         isWhite = !isWhite;\r
       }\r
     }\r
-    throw ReaderException.getInstance();\r
+    throw NotFoundException.getNotFoundInstance();\r
   }\r
 \r
   /**\r
@@ -322,9 +323,9 @@ public final class ITFReader extends OneDReader {
    *\r
    * @param counters the counts of runs of observed black/white/black/... values\r
    * @return The decoded digit\r
-   * @throws ReaderException if digit cannot be decoded\r
+   * @throws NotFoundException if digit cannot be decoded\r
    */\r
-  private static int decodeDigit(int[] counters) throws ReaderException {\r
+  private static int decodeDigit(int[] counters) throws NotFoundException {\r
 \r
     int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept\r
     int bestMatch = -1;\r
@@ -340,7 +341,7 @@ public final class ITFReader extends OneDReader {
     if (bestMatch >= 0) {\r
       return bestMatch;\r
                } else {\r
-                       throw ReaderException.getInstance();\r
+                       throw NotFoundException.getNotFoundInstance();\r
                }\r
        }\r
 \r
index ccdbe6d..40e4a8b 100644 (file)
@@ -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() {
index dcc32be..4524f3e 100644 (file)
@@ -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() {
index b21e9af..fc8bd8d 100644 (file)
 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;
 
 }
index 9b5e9cb..b90c1b8 100644 (file)
 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();
     }
   }
 
index be49027..803eaa6 100644 (file)
 
 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.</p>
    */
   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;
 
 }
index 3dd95a4..ef74b97 100644 (file)
@@ -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() {
index fda7a4c..1fcd1f1 100644 (file)
@@ -19,8 +19,9 @@ package com.google.zxing.pdf417;
 import com.google.zxing.BarcodeFormat;\r
 import com.google.zxing.BinaryBitmap;\r
 import com.google.zxing.DecodeHintType;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.Reader;\r
-import com.google.zxing.ReaderException;\r
 import com.google.zxing.Result;\r
 import com.google.zxing.ResultPoint;\r
 import com.google.zxing.common.BitMatrix;\r
@@ -46,14 +47,15 @@ public final class PDF417Reader implements Reader {
    * Locates and decodes a PDF417 code in an image.\r
    *\r
    * @return a String representing the content encoded by the PDF417 code\r
-   * @throws ReaderException if a PDF417 code cannot be found, or cannot be decoded\r
+   * @throws NotFoundException if a PDF417 code cannot be found,\r
+   * @throws FormatException if a PDF417 cannot be decoded\r
    */\r
-  public Result decode(BinaryBitmap image) throws ReaderException {\r
+  public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {\r
     return decode(image, null);\r
   }\r
 \r
   public Result decode(BinaryBitmap image, Hashtable hints)\r
-      throws ReaderException {\r
+      throws NotFoundException, FormatException {\r
     DecoderResult decoderResult;\r
     ResultPoint[] points;\r
     if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {\r
@@ -79,7 +81,7 @@ public final class PDF417Reader implements Reader {
    * around it. This is a specialized method that works exceptionally fast in this special\r
    * case.\r
    */\r
-  private static BitMatrix extractPureBits(BinaryBitmap image) throws ReaderException {\r
+  private static BitMatrix extractPureBits(BinaryBitmap image) throws NotFoundException {\r
     // Now need to determine module size in pixels\r
     BitMatrix matrix = image.getBlackMatrix();\r
     int height = matrix.getHeight();\r
@@ -92,7 +94,7 @@ public final class PDF417Reader implements Reader {
       borderWidth++;\r
     }\r
     if (borderWidth == minDimension) {\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
 \r
     // And then keep tracking across the top-left black module to determine module size\r
@@ -101,7 +103,7 @@ public final class PDF417Reader implements Reader {
       moduleEnd++;\r
     }\r
     if (moduleEnd == minDimension) {\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
 \r
     int moduleSize = moduleEnd - borderWidth;\r
@@ -112,13 +114,13 @@ public final class PDF417Reader implements Reader {
       rowEndOfSymbol--;\r
     }\r
     if (rowEndOfSymbol < 0) {\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
     rowEndOfSymbol++;\r
 \r
     // Make sure width of barcode is a multiple of module size\r
     if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) {\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
     int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;\r
 \r
@@ -129,7 +131,7 @@ public final class PDF417Reader implements Reader {
 \r
     int sampleDimension = borderWidth + (dimension - 1) * moduleSize;\r
     if (sampleDimension >= width || sampleDimension >= height) {\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
 \r
     // Now just read off the bits\r
index ca85e2f..03c12ac 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.pdf417.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.common.BitMatrix;\r
 \r
 /**\r
@@ -379,7 +379,7 @@ final class BitMatrixParser {
    * @param next        the next available index into the codewords array.\r
    * @return the next available index into the codeword array after processing\r
    *         this row.\r
-   * @throws ReaderException\r
+   * @throws NotFoundException\r
    */\r
   /*\r
   int processRow1(int[] rowCounters, int rowNumber, int rowHeight,\r
index a8cf592..0638843 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.pdf417.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
 import com.google.zxing.common.DecoderResult;\r
 \r
 /**\r
@@ -81,7 +81,7 @@ final class DecodedBitStreamParser {
   private DecodedBitStreamParser() {\r
   }\r
 \r
-  static DecoderResult decode(int[] codewords) throws ReaderException {\r
+  static DecoderResult decode(int[] codewords) throws FormatException {\r
     StringBuffer result = new StringBuffer(100);\r
     // Get compaction mode\r
     int codeIndex = 1;\r
@@ -120,7 +120,7 @@ final class DecodedBitStreamParser {
       if (codeIndex < codewords.length) {\r
         code = codewords[codeIndex++];\r
       } else {\r
-        throw ReaderException.getInstance();\r
+        throw FormatException.getFormatInstance();\r
       }\r
     }\r
     return new DecoderResult(null, result.toString(), null, null);\r
index fb722b6..1936c5a 100644 (file)
@@ -16,7 +16,9 @@
 \r
 package com.google.zxing.pdf417.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.common.BitMatrix;\r
 import com.google.zxing.common.DecoderResult;\r
 //import com.google.zxing.pdf417.reedsolomon.ReedSolomonDecoder;\r
@@ -44,9 +46,9 @@ public final class Decoder {
    *\r
    * @param image booleans representing white/black PDF417 modules\r
    * @return text and bytes encoded within the PDF417 Code\r
-   * @throws ReaderException if the PDF417 Code cannot be decoded\r
+   * @throws NotFoundException if the PDF417 Code cannot be decoded\r
    */\r
-  public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+  public DecoderResult decode(boolean[][] image) throws FormatException {\r
     int dimension = image.length;\r
     BitMatrix bits = new BitMatrix(dimension);\r
     for (int i = 0; i < dimension; i++) {\r
@@ -65,14 +67,14 @@ public final class Decoder {
    *\r
    * @param bits booleans representing white/black PDF417 Code modules\r
    * @return text and bytes encoded within the PDF417 Code\r
-   * @throws ReaderException if the PDF417 Code cannot be decoded\r
+   * @throws FormatException if the PDF417 Code cannot be decoded\r
    */\r
-  public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+  public DecoderResult decode(BitMatrix bits) throws FormatException {\r
     // Construct a parser to read the data codewords and error-correction level\r
     BitMatrixParser parser = new BitMatrixParser(bits);\r
     int[] codewords = parser.readCodewords();\r
     if (codewords == null || codewords.length == 0) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
 \r
     int ecLevel = parser.getECLevel();\r
@@ -91,27 +93,27 @@ public final class Decoder {
    *\r
    * @param codewords\r
    * @return an index to the first data codeword.\r
-   * @throws ReaderException\r
+   * @throws FormatException\r
    */\r
-  private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws ReaderException {\r
+  private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws FormatException {\r
     if (codewords.length < 4) {\r
       // Codeword array size should be at least 4 allowing for\r
       // Count CW, At least one Data CW, Error Correction CW, Error Correction CW\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     // The first codeword, the Symbol Length Descriptor, shall always encode the total number of data\r
     // codewords in the symbol, including the Symbol Length Descriptor itself, data codewords and pad\r
     // codewords, but excluding the number of error correction codewords.\r
     int numberOfCodewords = codewords[0];\r
     if (numberOfCodewords > codewords.length) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     if (numberOfCodewords == 0) {\r
       // Reset to the length of the array - 8 (Allow for at least level 3 Error Correction (8 Error Codewords)\r
       if (numECCodewords < codewords.length) {\r
         codewords[0] = codewords.length - numECCodewords;\r
       } else {\r
-        throw ReaderException.getInstance();\r
+        throw FormatException.getFormatInstance();\r
       }\r
     }\r
   }\r
@@ -121,15 +123,16 @@ public final class Decoder {
    * correct the errors in-place using Reed-Solomon error correction.</p>\r
    *\r
    * @param codewords   data and error correction codewords\r
-   * @throws ReaderException if error correction fails\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws ReaderException {\r
+  private static int correctErrors(int[] codewords, int[] erasures, int numECCodewords) throws FormatException {\r
     if ((erasures != null && erasures.length > numECCodewords / 2 + MAX_ERRORS) ||\r
         (numECCodewords < 0 || numECCodewords > MAX_EC_CODEWORDS)) {\r
       // Too many errors or EC Codewords is corrupted\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     // Try to correct the errors\r
+    // TODO enable error correction\r
     int result = 0; // rsDecoder.correctErrors(codewords, numECCodewords);\r
     if (erasures != null) {\r
       int numErasures = erasures.length;\r
@@ -138,7 +141,7 @@ public final class Decoder {
       }\r
       if (numErasures > MAX_ERRORS) {\r
         // Still too many errors\r
-        throw ReaderException.getInstance();\r
+        throw FormatException.getFormatInstance();\r
       }\r
     }\r
     return result;\r
index 6c448d8..7b841fa 100644 (file)
@@ -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 {
    * <p>Detects a PDF417 Code in an image, simply.</p>
    *
    * @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.
index 52002ae..d9abc93 100644 (file)
 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
index 028aa8e..7d516c6 100644 (file)
@@ -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;
 
index fd8071c..c6f79b3 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.qrcode.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
 import com.google.zxing.common.BitMatrix;\r
 \r
 /**\r
@@ -30,12 +30,12 @@ final class BitMatrixParser {
 \r
   /**\r
    * @param bitMatrix {@link BitMatrix} to parse\r
-   * @throws ReaderException if dimension is not >= 21 and 1 mod 4\r
+   * @throws FormatException if dimension is not >= 21 and 1 mod 4\r
    */\r
-  BitMatrixParser(BitMatrix bitMatrix) throws ReaderException {\r
+  BitMatrixParser(BitMatrix bitMatrix) throws FormatException {\r
     int dimension = bitMatrix.getDimension();\r
     if (dimension < 21 || (dimension & 0x03) != 1) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     this.bitMatrix = bitMatrix;\r
   }\r
@@ -44,10 +44,10 @@ final class BitMatrixParser {
    * <p>Reads format information from one of its two locations within the QR Code.</p>\r
    *\r
    * @return {@link FormatInformation} encapsulating the QR Code's format info\r
-   * @throws ReaderException if both format information locations cannot be parsed as\r
+   * @throws FormatException if both format information locations cannot be parsed as\r
    * the valid encoding of format information\r
    */\r
-  FormatInformation readFormatInformation() throws ReaderException {\r
+  FormatInformation readFormatInformation() throws FormatException {\r
 \r
     if (parsedFormatInfo != null) {\r
       return parsedFormatInfo;\r
@@ -87,17 +87,17 @@ final class BitMatrixParser {
     if (parsedFormatInfo != null) {\r
       return parsedFormatInfo;\r
     }\r
-    throw ReaderException.getInstance();\r
+    throw FormatException.getFormatInstance();\r
   }\r
 \r
   /**\r
    * <p>Reads version information from one of its two locations within the QR Code.</p>\r
    *\r
    * @return {@link Version} encapsulating the QR Code's version\r
-   * @throws ReaderException if both version information locations cannot be parsed as\r
+   * @throws FormatException if both version information locations cannot be parsed as\r
    * the valid encoding of version information\r
    */\r
-  Version readVersion() throws ReaderException {\r
+  Version readVersion() throws FormatException {\r
 \r
     if (parsedVersion != null) {\r
       return parsedVersion;\r
@@ -136,7 +136,7 @@ final class BitMatrixParser {
     if (parsedVersion != null && parsedVersion.getDimensionForVersion() == dimension) {\r
       return parsedVersion;\r
     }\r
-    throw ReaderException.getInstance();\r
+    throw FormatException.getFormatInstance();\r
   }\r
 \r
   private int copyBit(int i, int j, int versionBits) {\r
@@ -149,9 +149,9 @@ final class BitMatrixParser {
    * QR Code.</p>\r
    *\r
    * @return bytes encoded within the QR Code\r
-   * @throws ReaderException if the exact number of bytes expected is not read\r
+   * @throws FormatException if the exact number of bytes expected is not read\r
    */\r
-  byte[] readCodewords() throws ReaderException {\r
+  byte[] readCodewords() throws FormatException {\r
 \r
     FormatInformation formatInfo = readFormatInformation();\r
     Version version = readVersion();\r
@@ -200,7 +200,7 @@ final class BitMatrixParser {
       readingUp ^= true; // readingUp = !readingUp; // switch directions\r
     }\r
     if (resultOffset != version.getTotalCodewords()) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     return result;\r
   }\r
index 55ff636..25907e3 100644 (file)
@@ -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]);
     }
index 6a576f8..f7d5273 100644 (file)
@@ -16,7 +16,9 @@
 \r
 package com.google.zxing.qrcode.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.ChecksumException;\r
+import com.google.zxing.FormatException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.common.BitMatrix;\r
 import com.google.zxing.common.DecoderResult;\r
 import com.google.zxing.common.reedsolomon.GF256;\r
@@ -39,7 +41,8 @@ public final class Decoder {
     rsDecoder = new ReedSolomonDecoder(GF256.QR_CODE_FIELD);\r
   }\r
 \r
-  public DecoderResult decode(boolean[][] image) throws ReaderException {\r
+  public DecoderResult decode(boolean[][] image)\r
+      throws ChecksumException, FormatException, NotFoundException {\r
     return decode(image, null);\r
   }\r
 \r
@@ -49,9 +52,12 @@ public final class Decoder {
    *\r
    * @param image booleans representing white/black QR Code modules\r
    * @return text and bytes encoded within the QR Code\r
-   * @throws ReaderException if the QR Code cannot be decoded\r
+   * @throws NotFoundException if the QR Code cannot be found\r
+   * @throws FormatException if the QR Code cannot be decoded\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  public DecoderResult decode(boolean[][] image, Hashtable hints) throws ReaderException {\r
+  public DecoderResult decode(boolean[][] image, Hashtable hints)\r
+      throws ChecksumException, FormatException, NotFoundException {\r
     int dimension = image.length;\r
     BitMatrix bits = new BitMatrix(dimension);\r
     for (int i = 0; i < dimension; i++) {\r
@@ -64,7 +70,7 @@ public final class Decoder {
     return decode(bits, hints);\r
   }\r
 \r
-  public DecoderResult decode(BitMatrix bits) throws ReaderException {\r
+  public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException, NotFoundException {\r
     return decode(bits, null);\r
   }\r
 \r
@@ -73,9 +79,12 @@ public final class Decoder {
    *\r
    * @param bits booleans representing white/black QR Code modules\r
    * @return text and bytes encoded within the QR Code\r
-   * @throws ReaderException if the QR Code cannot be decoded\r
+   * @throws NotFoundException if the QR Code cannot be found\r
+   * @throws FormatException if the QR Code cannot be decoded\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  public DecoderResult decode(BitMatrix bits, Hashtable hints) throws ReaderException {\r
+  public DecoderResult decode(BitMatrix bits, Hashtable hints)\r
+      throws NotFoundException, FormatException, ChecksumException {\r
 \r
     // Construct a parser and read version, error-correction level\r
     BitMatrixParser parser = new BitMatrixParser(bits);\r
@@ -116,9 +125,9 @@ public final class Decoder {
    *\r
    * @param codewordBytes data and error correction codewords\r
    * @param numDataCodewords number of codewords that are data bytes\r
-   * @throws ReaderException if error correction fails\r
+   * @throws ChecksumException if error correction fails\r
    */\r
-  private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ReaderException {\r
+  private void correctErrors(byte[] codewordBytes, int numDataCodewords) throws ChecksumException {\r
     int numCodewords = codewordBytes.length;\r
     // First read into an array of ints\r
     int[] codewordsInts = new int[numCodewords];\r
@@ -129,7 +138,7 @@ public final class Decoder {
     try {\r
       rsDecoder.decode(codewordsInts, numECCodewords);\r
     } catch (ReedSolomonException rse) {\r
-      throw ReaderException.getInstance();\r
+      throw ChecksumException.getChecksumInstance();\r
     }\r
     // Copy back into array of bytes -- only need to worry about the bytes that were data\r
     // We don't care about errors in the error-correction codewords\r
index 823bf2b..497a63f 100755 (executable)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.qrcode.decoder;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.FormatException;\r
 import com.google.zxing.common.BitMatrix;\r
 \r
 /**\r
@@ -91,16 +91,16 @@ public final class Version {
    *\r
    * @param dimension dimension in modules\r
    * @return {@link Version} for a QR Code of that dimension\r
-   * @throws ReaderException if dimension is not 1 mod 4\r
+   * @throws FormatException if dimension is not 1 mod 4\r
    */\r
-  public static Version getProvisionalVersionForDimension(int dimension) throws ReaderException {\r
+  public static Version getProvisionalVersionForDimension(int dimension) throws FormatException {\r
     if (dimension % 4 != 1) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
     try {\r
       return getVersionForNumber((dimension - 17) >> 2);\r
     } catch (IllegalArgumentException iae) {\r
-      throw ReaderException.getInstance();\r
+      throw FormatException.getFormatInstance();\r
     }\r
   }\r
 \r
index 83a035d..c85cd72 100644 (file)
@@ -16,7 +16,7 @@
 \r
 package com.google.zxing.qrcode.detector;\r
 \r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.ResultPoint;\r
 import com.google.zxing.ResultPointCallback;\r
 import com.google.zxing.common.BitMatrix;\r
@@ -82,9 +82,9 @@ final class AlignmentPatternFinder {
    * it's pretty performance-critical and so is written to be fast foremost.</p>\r
    *\r
    * @return {@link AlignmentPattern} if found\r
-   * @throws ReaderException if not found\r
+   * @throws NotFoundException if not found\r
    */\r
-  AlignmentPattern find() throws ReaderException {\r
+  AlignmentPattern find() throws NotFoundException {\r
     int startX = this.startX;\r
     int height = this.height;\r
     int maxJ = startX + width;\r
@@ -150,7 +150,7 @@ final class AlignmentPatternFinder {
       return (AlignmentPattern) possibleCenters.elementAt(0);\r
     }\r
 \r
-    throw ReaderException.getInstance();\r
+    throw NotFoundException.getNotFoundInstance();\r
   }\r
 \r
   /**\r
index ae7d9f5..82d50a6 100644 (file)
@@ -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 {
    * <p>Detects a QR Code in an image, simply.</p>
    *
    * @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 {
    * <p>Detects a QR Code in an image, simply.</p>
    *
    * @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);
index 776f726..6c388a8 100755 (executable)
 package com.google.zxing.qrcode.detector;\r
 \r
 import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.ReaderException;\r
+import com.google.zxing.NotFoundException;\r
 import com.google.zxing.ResultPoint;\r
 import com.google.zxing.ResultPointCallback;\r
+import com.google.zxing.common.BitMatrix;\r
 import com.google.zxing.common.Collections;\r
 import com.google.zxing.common.Comparator;\r
-import com.google.zxing.common.BitMatrix;\r
 \r
 import java.util.Hashtable;\r
 import java.util.Vector;\r
@@ -72,7 +72,7 @@ public class FinderPatternFinder {
     return possibleCenters;\r
   }\r
 \r
-  FinderPatternInfo find(Hashtable hints) throws ReaderException {\r
+  FinderPatternInfo find(Hashtable hints) throws NotFoundException {\r
     boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);\r
     int maxI = image.getHeight();\r
     int maxJ = image.getWidth();\r
@@ -488,14 +488,14 @@ public class FinderPatternFinder {
    * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are\r
    *         those that have been detected at least {@link #CENTER_QUORUM} times, and whose module\r
    *         size differs from the average among those patterns the least\r
-   * @throws ReaderException if 3 such finder patterns do not exist\r
+   * @throws NotFoundException if 3 such finder patterns do not exist\r
    */\r
-  private FinderPattern[] selectBestPatterns() throws ReaderException {\r
+  private FinderPattern[] selectBestPatterns() throws NotFoundException {\r
 \r
     int startSize = possibleCenters.size();\r
     if (startSize < 3) {\r
       // Couldn't find enough finder patterns\r
-      throw ReaderException.getInstance();\r
+      throw NotFoundException.getNotFoundInstance();\r
     }\r
 \r
     // Filter outlier possibilities whose module size is too different\r
index 55c1bca..fd02c3b 100644 (file)
@@ -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
index 9c2ecaa..6854844 100644 (file)
@@ -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;
 
index d44c340..08bf2c5 100644 (file)
@@ -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}.
index 152d1c0..c3fc5fd 100644 (file)
@@ -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}.
index 292da83..f10820e 100644 (file)
@@ -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}.
index 8a25849..4f3b966 100644 (file)
@@ -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}.
index 36a95cd..d1f53d2 100644 (file)
@@ -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}.
index 663bfa4..6dc2848 100644 (file)
@@ -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}.
index 9e11098..7d754fe 100644 (file)
@@ -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}.
index d35cec2..055f86c 100644 (file)
@@ -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}.
index 2ef12b4..d078fa1 100644 (file)
@@ -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)
index 88f8249..74fdda8 100644 (file)
@@ -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.
index 9d215f9..9dc0978 100644 (file)
@@ -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)};
index 819031a..1e15454 100644 (file)
@@ -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;
 
 /**
index 1eeb1cf..d3bc6dc 100644 (file)
@@ -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;
 
 /**
index 5478d98..c0c4bab 100644 (file)
@@ -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
index 3a88d67..d3f9e6f 100644 (file)
@@ -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;
 
 /**
index b3429a9..f79a97b 100644 (file)
@@ -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;
 
 /**
index 607e0c8..0070031 100644 (file)
 
 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)
  */
index bd0ac2a..2515f55 100644 (file)
@@ -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;
 
 /**
index cddb2d9..285aa22 100644 (file)
@@ -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;
 
 /**
index f17ec52..8adccd7 100644 (file)
@@ -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;
 
 /**
index e4cd667..b1c4dbc 100644 (file)
@@ -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;
 
 /**
index 316bd02..d18eab6 100644 (file)
@@ -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;
 
 /**
index b005ffd..4e6c4c5 100644 (file)
@@ -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;
 
 /**
index cab69b7..885402a 100644 (file)
@@ -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;
 
 /**
index ff5e129..0cc9b4a 100644 (file)
@@ -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;
 
 /**
index b0e1645..e789ce9 100644 (file)
@@ -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;
 
 /**
index a5bac91..b31caa4 100644 (file)
@@ -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;
 
 /**
index 2901ac1..bcdba72 100644 (file)
@@ -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;
 
 /**
index 49db0c9..3ef4ae6 100644 (file)
@@ -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;
 
 /**
index 8fca08e..a2cefdd 100644 (file)
@@ -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;
 
 /**
index 8078b07..ddd1052 100644 (file)
@@ -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
index c92d872..64c5d4e 100644 (file)
@@ -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());
     }
index a7ad9d6..61ca47a 100644 (file)
@@ -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
index 538e59a..2cbd5fe 100644 (file)
@@ -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) {
 
       }
     }
index adeedd8..3926f0f 100644 (file)
@@ -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 (file)
index 0000000..a88ff9b
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2008 ZXing authors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ 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.
+ -->
+<!-- Author: Sean Owen -->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
+<jsp:directive.page contentType="text/html" session="false"/>
+<jsp:scriptlet>response.setHeader("Cache-Control", "public");</jsp:scriptlet>
+<jsp:text><![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">]]></jsp:text>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+  <head>
+    <title>No Barcode Found</title>
+    <link rel="stylesheet" href="style.css" type="text/css"/>    
+  </head>
+  <body>
+    <div id="header"><h1><img src="zxing-icon.png" height="32" width="32" alt=""/> Barcode Format Problem</h1></div>
+    <p>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.
+    </p>
+    <jsp:include page="analytics.jspx"/>
+  </body>
+</html>
+</jsp:root>