Created a WriterException class and updated a bunch of documentation.
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 18 Nov 2008 21:46:24 +0000 (21:46 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Tue, 18 Nov 2008 21:46:24 +0000 (21:46 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@725 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/MultiFormatWriter.java
core/src/com/google/zxing/Writer.java
core/src/com/google/zxing/WriterException.java [new file with mode: 0644]
core/src/com/google/zxing/qrcode/QRCodeWriter.java

index 2913de1..a57ea7b 100644 (file)
@@ -21,16 +21,22 @@ import com.google.zxing.qrcode.QRCodeWriter;
 
 import java.util.Hashtable;
 
+/**
+ * This is a factory class which finds the appropriate Writer subclass for the BarcodeFormat
+ * requested and encodes the barcode with the supplied contents.
+ *
+ * @author dswitkin@google.com (Daniel Switkin)
+ */
 public final class MultiFormatWriter implements Writer {
 
   public ByteMatrix encode(byte[] contents, BarcodeFormat format, int width,
-      int height) throws Exception {
+      int height) throws WriterException {
 
     return encode(contents, format, width, height, null);
   }
 
   public ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height,
-      Hashtable hints) throws Exception {
+      Hashtable hints) throws WriterException {
 
     if (format == BarcodeFormat.QR_CODE) {
       return new QRCodeWriter().encode(contents, format, width, height, hints);
index 21fcc3f..936f1dd 100644 (file)
@@ -20,6 +20,11 @@ import com.google.zxing.common.ByteMatrix;
 
 import java.util.Hashtable;
 
+/**
+ * The base class for all objects which encode/generate a barcode image.
+ *
+ * @author dswitkin@google.com (Daniel Switkin)
+ */
 public interface Writer {
 
   /**
@@ -31,7 +36,8 @@ public interface Writer {
    * @param height The preferred height in pixels
    * @return The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
    */
-  ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height) throws Exception;
+  ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height)
+      throws WriterException;
 
   /**
    *
@@ -43,6 +49,6 @@ public interface Writer {
    * @return The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
    */
   ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height, Hashtable hints)
-      throws Exception;
+      throws WriterException;
 
 }
diff --git a/core/src/com/google/zxing/WriterException.java b/core/src/com/google/zxing/WriterException.java
new file mode 100644 (file)
index 0000000..cf1ec16
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package com.google.zxing;
+
+/**
+ * A base class which covers the range of exceptions which may occur when encoding a barcode using
+ * the Writer framework.
+ *
+ * @author dswitkin@google.com (Daniel Switkin)
+ */
+public class WriterException extends Exception {
+
+  public WriterException(String message) {
+    super(message);
+  }
+
+}
index f223935..4c5c6e2 100644 (file)
@@ -18,6 +18,7 @@ package com.google.zxing.qrcode;
 
 import com.google.zxing.BarcodeFormat;
 import com.google.zxing.Writer;
+import com.google.zxing.WriterException;
 import com.google.zxing.common.ByteMatrix;
 import com.google.zxing.qrcode.encoder.ByteArray;
 import com.google.zxing.qrcode.encoder.Encoder;
@@ -25,14 +26,21 @@ import com.google.zxing.qrcode.encoder.QRCode;
 
 import java.util.Hashtable;
 
+/**
+ * This object renders a QR Code as a ByteMatrix 2D array of greyscale values.
+ *
+ * @author dswitkin@google.com (Daniel Switkin)
+ */
 public final class QRCodeWriter implements Writer {
 
-  public ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height) {
+  public ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height)
+      throws WriterException {
 
     return encode(contents, format, width, height, null);
   }
 
-  public ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height, Hashtable hints) {
+  public ByteMatrix encode(byte[] contents, BarcodeFormat format, int width, int height,
+      Hashtable hints) throws WriterException {
 
     if (contents == null || contents.length == 0) {
       throw new IllegalArgumentException("Found empty contents");
@@ -53,8 +61,7 @@ public final class QRCodeWriter implements Writer {
     if (Encoder.Encode(new ByteArray(contents), errorCorrectionLevel, code)) {
       return renderResult(code, width, height);
     } else {
-      // TODO need a "WriterException" or something
-      throw new RuntimeException("Could not generate a QR Code");
+      throw new WriterException("Could not generate a QR Code");
     }
   }