X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=javase%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2se%2FCommandLineRunner.java;h=cac8e4ff797e2bb50f53855e724cc63efb1e2e7d;hb=59a995beefc05ba1a676bd07997f24bdfe87d50b;hp=b675eef72ff3f91ceab10bb60abeb33bf01bdfa8;hpb=93dc44adb7dbf108975ec09d061229b80f8cc834;p=zxing.git diff --git a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java index b675eef7..cac8e4ff 100644 --- a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java +++ b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 Google Inc. + * 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. @@ -17,14 +17,16 @@ package com.google.zxing.client.j2se; import com.google.zxing.DecodeHintType; +import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.MultiFormatReader; import com.google.zxing.ReaderException; -import com.google.zxing.MonochromeBitmapSource; +import com.google.zxing.Result; 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; @@ -59,7 +61,8 @@ public final class CommandLineRunner { } } - private static void decodeOneArgument(String argument, Hashtable hints) throws Exception { + private static void decodeOneArgument(String argument, Hashtable hints) + throws Exception { File inputFile = new File(argument); if (inputFile.exists()) { if (inputFile.isDirectory()) { @@ -87,15 +90,21 @@ public final class CommandLineRunner { } private static boolean decode(URI uri, Hashtable 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; } try { MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image); - String result = new MultiFormatReader().decode(source, hints).getText(); - System.out.println(uri.toString() + ": " + result); + Result result = new MultiFormatReader().decode(source, hints); + System.out.println(uri.toString() + " (format: " + result.getBarcodeFormat() + "):\n" + + result.getText()); return true; } catch (ReaderException e) { System.out.println(uri.toString() + ": No barcode found");