"Split" ReaderException into subclasses to enable more useful error reporting
[zxing.git] / core / src / com / google / zxing / datamatrix / DataMatrixReader.java
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