Tiny changes to System.err usage, closed a stream, saved a reused Pattern
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sat, 26 Sep 2009 13:25:37 +0000 (13:25 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sat, 26 Sep 2009 13:25:37 +0000 (13:25 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1064 59b500cc-1b3d-0410-9834-0bbf25fbcc57

javase/src/com/google/zxing/client/j2se/CommandLineRunner.java
javase/src/com/google/zxing/client/j2se/ImageConverter.java
zxingorg/src/com/google/zxing/web/DoSFilter.java

index 5138e3a..a607cd6 100644 (file)
@@ -75,7 +75,7 @@ public final class CommandLineRunner {
       } else if ("--dump_black_point".equals(arg)) {
         dumpBlackPoint = true;
       } else if (arg.startsWith("-")) {
-        System.out.println("Unknown command line option " + arg);
+        System.err.println("Unknown command line option " + arg);
         printUsage();
         return;
       }
@@ -106,11 +106,11 @@ public final class CommandLineRunner {
   }
 
   private static void printUsage() {
-    System.out.println("Decode barcode images using the ZXing library\n");
-    System.out.println("usage: CommandLineRunner { file | dir | url } [ options ]");
-    System.out.println("  --try_harder: Use the TRY_HARDER hint, default is normal (mobile) mode");
-    System.out.println("  --dump_results: Write the decoded contents to input.txt");
-    System.out.println("  --dump_black_point: Compare black point algorithms as input.mono.png");
+    System.err.println("Decode barcode images using the ZXing library\n");
+    System.err.println("usage: CommandLineRunner { file | dir | url } [ options ]");
+    System.err.println("  --try_harder: Use the TRY_HARDER hint, default is normal (mobile) mode");
+    System.err.println("  --dump_results: Write the decoded contents to input.txt");
+    System.err.println("  --dump_black_point: Compare black point algorithms as input.mono.png");
   }
 
   private static void decodeOneArgument(String argument, Hashtable<DecodeHintType, Object> hints,
@@ -282,13 +282,22 @@ public final class CommandLineRunner {
       resultName = resultName.substring(0, pos);
     }
     resultName += ".mono.png";
+    OutputStream outStream = null;
     try {
-      OutputStream outStream = new FileOutputStream(resultName);
+      outStream = new FileOutputStream(resultName);
       ImageIO.write(result, "png", outStream);
     } catch (FileNotFoundException e) {
-      System.out.println("Could not create " + resultName);
+      System.err.println("Could not create " + resultName);
     } catch (IOException e) {
-      System.out.println("Could not write to " + resultName);
+      System.err.println("Could not write to " + resultName);
+    } finally {
+      try {
+        if (outStream != null) {
+          outStream.close();
+        }
+      } catch (IOException ioe) {
+        // continue
+      }
     }
   }
 
index 895424e..4b4cd16 100644 (file)
@@ -60,7 +60,7 @@ public final class ImageConverter {
       } else if ("-2d".equals(arg)) {
         rowSampling = false;
       } else if (arg.startsWith("-")) {
-        System.out.println("Ignoring unrecognized option: " + arg);
+        System.err.println("Ignoring unrecognized option: " + arg);
       }
     }
     for (String arg : args) {
index 083dd30..177fc2b 100755 (executable)
@@ -33,6 +33,7 @@ import java.util.HashSet;
 import java.util.Set;\r
 import java.util.Timer;\r
 import java.util.TimerTask;\r
+import java.util.regex.Pattern;\r
 \r
 /**\r
  * A {@link Filter} that rejects requests from hosts that are sending too many\r
@@ -45,6 +46,7 @@ public final class DoSFilter implements Filter {
   private static final int MAX_ACCESSES_PER_IP_PER_TIME = 10;\r
   private static final long MAX_ACCESS_INTERVAL_MSEC = 10L * 1000L;\r
   private static final long UNBAN_INTERVAL_MSEC = 60L * 60L * 1000L;\r
+  private static final Pattern COMMA_PATTERN = Pattern.compile(",");\r
 \r
   private final IPTrie numRecentAccesses;\r
   private final Timer timer;\r
@@ -63,7 +65,7 @@ public final class DoSFilter implements Filter {
     context = filterConfig.getServletContext();\r
     String bannedIPs = filterConfig.getInitParameter("bannedIPs");\r
     if (bannedIPs != null) {\r
-      for (String ip : bannedIPs.split(",")) {\r
+      for (String ip : COMMA_PATTERN.split(bannedIPs)) {\r
         manuallyBannedIPAddresses.add(ip.trim());\r
       }\r
     }\r