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
This commit is contained in:
srowen 2009-09-26 13:25:37 +00:00
parent 77a263dd91
commit 7d0acf8bd9
3 changed files with 22 additions and 11 deletions

View file

@ -75,7 +75,7 @@ public final class CommandLineRunner {
} else if ("--dump_black_point".equals(arg)) { } else if ("--dump_black_point".equals(arg)) {
dumpBlackPoint = true; dumpBlackPoint = true;
} else if (arg.startsWith("-")) { } else if (arg.startsWith("-")) {
System.out.println("Unknown command line option " + arg); System.err.println("Unknown command line option " + arg);
printUsage(); printUsage();
return; return;
} }
@ -106,11 +106,11 @@ public final class CommandLineRunner {
} }
private static void printUsage() { private static void printUsage() {
System.out.println("Decode barcode images using the ZXing library\n"); System.err.println("Decode barcode images using the ZXing library\n");
System.out.println("usage: CommandLineRunner { file | dir | url } [ options ]"); System.err.println("usage: CommandLineRunner { file | dir | url } [ options ]");
System.out.println(" --try_harder: Use the TRY_HARDER hint, default is normal (mobile) mode"); System.err.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.err.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(" --dump_black_point: Compare black point algorithms as input.mono.png");
} }
private static void decodeOneArgument(String argument, Hashtable<DecodeHintType, Object> hints, private static void decodeOneArgument(String argument, Hashtable<DecodeHintType, Object> hints,
@ -282,13 +282,22 @@ public final class CommandLineRunner {
resultName = resultName.substring(0, pos); resultName = resultName.substring(0, pos);
} }
resultName += ".mono.png"; resultName += ".mono.png";
OutputStream outStream = null;
try { try {
OutputStream outStream = new FileOutputStream(resultName); outStream = new FileOutputStream(resultName);
ImageIO.write(result, "png", outStream); ImageIO.write(result, "png", outStream);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
System.out.println("Could not create " + resultName); System.err.println("Could not create " + resultName);
} catch (IOException e) { } 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
}
} }
} }

View file

@ -60,7 +60,7 @@ public final class ImageConverter {
} else if ("-2d".equals(arg)) { } else if ("-2d".equals(arg)) {
rowSampling = false; rowSampling = false;
} else if (arg.startsWith("-")) { } else if (arg.startsWith("-")) {
System.out.println("Ignoring unrecognized option: " + arg); System.err.println("Ignoring unrecognized option: " + arg);
} }
} }
for (String arg : args) { for (String arg : args) {

View file

@ -33,6 +33,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.regex.Pattern;
/** /**
* A {@link Filter} that rejects requests from hosts that are sending too many * 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 int MAX_ACCESSES_PER_IP_PER_TIME = 10;
private static final long MAX_ACCESS_INTERVAL_MSEC = 10L * 1000L; private static final long MAX_ACCESS_INTERVAL_MSEC = 10L * 1000L;
private static final long UNBAN_INTERVAL_MSEC = 60L * 60L * 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 IPTrie numRecentAccesses;
private final Timer timer; private final Timer timer;
@ -63,7 +65,7 @@ public final class DoSFilter implements Filter {
context = filterConfig.getServletContext(); context = filterConfig.getServletContext();
String bannedIPs = filterConfig.getInitParameter("bannedIPs"); String bannedIPs = filterConfig.getInitParameter("bannedIPs");
if (bannedIPs != null) { if (bannedIPs != null) {
for (String ip : bannedIPs.split(",")) { for (String ip : COMMA_PATTERN.split(bannedIPs)) {
manuallyBannedIPAddresses.add(ip.trim()); manuallyBannedIPAddresses.add(ip.trim());
} }
} }