From 7d0acf8bd9d152015e81c461693221bd9d17ddf7 Mon Sep 17 00:00:00 2001 From: srowen Date: Sat, 26 Sep 2009 13:25:37 +0000 Subject: [PATCH] Tiny changes to System.err usage, closed a stream, saved a reused Pattern git-svn-id: https://zxing.googlecode.com/svn/trunk@1064 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/client/j2se/CommandLineRunner.java | 27 ++++++++++++------- .../zxing/client/j2se/ImageConverter.java | 2 +- .../src/com/google/zxing/web/DoSFilter.java | 4 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java index 5138e3a47..a607cd68f 100644 --- a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java +++ b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java @@ -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 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 + } } } diff --git a/javase/src/com/google/zxing/client/j2se/ImageConverter.java b/javase/src/com/google/zxing/client/j2se/ImageConverter.java index 895424e74..4b4cd1653 100644 --- a/javase/src/com/google/zxing/client/j2se/ImageConverter.java +++ b/javase/src/com/google/zxing/client/j2se/ImageConverter.java @@ -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) { diff --git a/zxingorg/src/com/google/zxing/web/DoSFilter.java b/zxingorg/src/com/google/zxing/web/DoSFilter.java index 083dd30f5..177fc2bc4 100755 --- a/zxingorg/src/com/google/zxing/web/DoSFilter.java +++ b/zxingorg/src/com/google/zxing/web/DoSFilter.java @@ -33,6 +33,7 @@ import java.util.HashSet; import java.util.Set; import java.util.Timer; import java.util.TimerTask; +import java.util.regex.Pattern; /** * A {@link Filter} that rejects requests from hosts that are sending too many @@ -45,6 +46,7 @@ public final class DoSFilter implements Filter { private static final int MAX_ACCESSES_PER_IP_PER_TIME = 10; private static final long MAX_ACCESS_INTERVAL_MSEC = 10L * 1000L; private static final long UNBAN_INTERVAL_MSEC = 60L * 60L * 1000L; + private static final Pattern COMMA_PATTERN = Pattern.compile(","); private final IPTrie numRecentAccesses; private final Timer timer; @@ -63,7 +65,7 @@ public final class DoSFilter implements Filter { context = filterConfig.getServletContext(); String bannedIPs = filterConfig.getInitParameter("bannedIPs"); if (bannedIPs != null) { - for (String ip : bannedIPs.split(",")) { + for (String ip : COMMA_PATTERN.split(bannedIPs)) { manuallyBannedIPAddresses.add(ip.trim()); } }