X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=javase%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2se%2FCommandLineRunner.java;h=8ca8a97c88cbe9977a6a59757fe4f7923f5b6423;hp=20d674b9f3739d8319ad481d5b9505ff6fbfcc75;hb=0e6441475c83c367ff7a8386ef88b8046927db7b;hpb=6b69e75db67222e92297a07e5197118215b445fa
diff --git a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java
index 20d674b9..8ca8a97c 100644
--- a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java
+++ b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java
@@ -29,35 +29,61 @@ import java.net.URI;
import java.util.Hashtable;
/**
- *
Simply attempts to decode the barcode in the image indicated by the single argument
- * to this program, which may be file or a URI. The raw text is printed.
+ * This simple command line utility decodes files, directories of files, or URIs which are passed
+ * as arguments. By default it uses the normal decoding algorithms, but you can pass --try_harder to
+ * request that hint. The raw text of each barcode is printed, and when running against directories,
+ * summary statistics are also displayed.
*
* @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
*/
public final class CommandLineRunner {
+ private static Hashtable hints = null;
+
private CommandLineRunner() {
}
public static void main(String[] args) throws Exception {
- File inputFile = new File(args[0]);
+ for (int x = 0; x < args.length; x++) {
+ if (args[x].equals("--try_harder")) {
+ hints = new Hashtable(3);
+ hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
+ } else if (args[x].startsWith("--")) {
+ System.out.println("Unknown command line option " + args[x]);
+ return;
+ }
+ }
+ for (int x = 0; x < args.length; x++) {
+ if (!args[x].startsWith("--")) {
+ decodeOneArgument(args[x]);
+ }
+ }
+ }
+
+ private static void decodeOneArgument(String argument) throws Exception {
+ File inputFile = new File(argument);
if (inputFile.exists()) {
if (inputFile.isDirectory()) {
int successful = 0;
int total = 0;
for (File input : inputFile.listFiles()) {
+ String filename = input.getName().toLowerCase();
+ // Skip hidden files and text files (the latter is found in the blackbox tests).
+ if (filename.startsWith(".") || filename.endsWith(".txt")) {
+ continue;
+ }
if (decode(input.toURI())) {
successful++;
}
total++;
}
System.out.println("\nDecoded " + successful + " files out of " + total +
- " successfully (" + (successful * 100 / total) + "%)");
+ " successfully (" + (successful * 100 / total) + "%)\n");
} else {
decode(inputFile.toURI());
}
} else {
- decode(new URI(args[0]));
+ decode(new URI(argument));
}
}
@@ -68,8 +94,6 @@ public final class CommandLineRunner {
return false;
}
try {
- Hashtable hints = new Hashtable(3);
- hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image);
String result = new MultiFormatReader().decode(source, hints).getText();
System.out.println(uri.toString() + ": " + result);