Avoid a few more rare exceptions

git-svn-id: https://zxing.googlecode.com/svn/trunk@2284 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-05-10 09:00:48 +00:00
parent b73efdfba1
commit 500872c9ff
2 changed files with 25 additions and 4 deletions

View file

@ -186,6 +186,9 @@ public final class Code93Reader extends OneDReader {
for (int i = 0; i < length; i++) {
char c = encoded.charAt(i);
if (c >= 'a' && c <= 'd') {
if (i >= length - 1) {
throw FormatException.getFormatInstance();
}
char next = encoded.charAt(i + 1);
char decodedChar = '\0';
switch (c) {

View file

@ -45,8 +45,10 @@ import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -129,18 +131,34 @@ public final class DecodeServlet extends HttpServlet {
imageURIString = "http://" + imageURIString;
}
URI imageURI;
URL imageURL;
try {
imageURI = new URI(imageURIString);
imageURL = new URI(imageURIString).toURL();
} catch (URISyntaxException urise) {
if (log.isLoggable(Level.FINE)) {
log.fine("URI was not valid: " + imageURIString);
}
response.sendRedirect("badurl.jspx");
return;
} catch (MalformedURLException mue) {
if (log.isLoggable(Level.FINE)) {
log.fine("URI was not valid: " + imageURIString);
}
response.sendRedirect("badurl.jspx");
return;
}
HttpURLConnection connection;
try {
connection = (HttpURLConnection) imageURL.openConnection();
} catch (IllegalArgumentException iae) {
if (log.isLoggable(Level.FINE)) {
log.fine("URI could not be opened: " + imageURL);
}
response.sendRedirect("badurl.jspx");
return;
}
HttpURLConnection connection = (HttpURLConnection) imageURI.toURL().openConnection();
connection.setAllowUserInteraction(false);
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
@ -182,7 +200,7 @@ public final class DecodeServlet extends HttpServlet {
return;
}
log.info("Decoding " + imageURI);
log.info("Decoding " + imageURL);
processStream(is, request, response);
} catch (IOException ioe) {