Improved error message when file/URI is mistyped.
[zxing.git] / javase / src / com / google / zxing / client / j2se / CommandLineRunner.java
index 0ac86d8..cac8e4f 100644 (file)
@@ -26,6 +26,7 @@ import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.net.URI;
 import java.util.Hashtable;
 
@@ -89,7 +90,12 @@ public final class CommandLineRunner {
   }
 
   private static boolean decode(URI uri, Hashtable<DecodeHintType, Object> hints) throws IOException {
-    BufferedImage image = ImageIO.read(uri.toURL());
+    BufferedImage image;
+    try {
+      image = ImageIO.read(uri.toURL());
+    } catch (IllegalArgumentException iae) {
+      throw new FileNotFoundException("Resource not found: " + uri);
+    }
     if (image == null) {
       System.err.println(uri.toString() + ": Could not load image");
       return false;
@@ -97,8 +103,8 @@ public final class CommandLineRunner {
     try {
       MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image);
       Result result = new MultiFormatReader().decode(source, hints);
-      System.out.println(uri.toString() + ": " + result.getText() + " format: " +
-          result.getBarcodeFormat());
+      System.out.println(uri.toString() + " (format: " + result.getBarcodeFormat() + "):\n" +
+          result.getText());
       return true;
     } catch (ReaderException e) {
       System.out.println(uri.toString() + ": No barcode found");