} 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;
}
}
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,
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
+ }
}
}
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
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
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