diff --git a/zxing.appspot.com/pom.xml b/zxing.appspot.com/pom.xml index 89af913d6..92acdb158 100644 --- a/zxing.appspot.com/pom.xml +++ b/zxing.appspot.com/pom.xml @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9 + 2.9.1 1.7
provided - org.apache.commons - commons-lang3 - 3.1 + org.apache.commons + commons-lang3 + 3.1 - commons-io - commons-io - 2.4 + commons-io + commons-io + 2.4 - commons-fileupload - commons-fileupload - 1.3 + commons-fileupload + commons-fileupload + 1.3 + + + com.google.guava + guava + 15.0 diff --git a/zxingorg/src/com/google/zxing/web/DecodeServlet.java b/zxingorg/src/com/google/zxing/web/DecodeServlet.java index 66a23585b..49e07723f 100644 --- a/zxingorg/src/com/google/zxing/web/DecodeServlet.java +++ b/zxingorg/src/com/google/zxing/web/DecodeServlet.java @@ -16,6 +16,11 @@ package com.google.zxing.web; +import com.google.common.base.Charsets; +import com.google.common.collect.Lists; +import com.google.common.io.Resources; +import com.google.common.net.HttpHeaders; +import com.google.common.net.MediaType; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.ChecksumException; @@ -43,11 +48,9 @@ import org.apache.commons.io.FileCleaningTracker; import java.awt.color.CMMException; import java.awt.image.BufferedImage; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.HttpURLConnection; @@ -55,8 +58,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.EnumMap; @@ -84,13 +85,11 @@ public final class DecodeServlet extends HttpServlet { private static final Logger log = Logger.getLogger(DecodeServlet.class.getName()); - private static final Charset UTF8 = Charset.forName("UTF-8"); - - // No real reason to let people upload more than a 2MB image - private static final long MAX_IMAGE_SIZE = 2000000L; + // No real reason to let people upload more than a 4MB image + private static final long MAX_IMAGE_SIZE = 4000000L; // No real reason to deal with more than maybe 8.3 megapixels private static final int MAX_PIXELS = 1 << 23; - private static final byte[] REMAINDER_BUFFER = new byte[8192]; + private static final byte[] REMAINDER_BUFFER = new byte[32768]; private static final Map HINTS; private static final Map HINTS_PURE; @@ -103,7 +102,7 @@ public final class DecodeServlet extends HttpServlet { } private DiskFileItemFactory diskFileItemFactory; - private Collection blockedURLSubstrings; + private Iterable blockedURLSubstrings; @Override public void init(ServletConfig servletConfig) throws ServletException { @@ -115,13 +114,9 @@ public final class DecodeServlet extends HttpServlet { diskFileItemFactory = new DiskFileItemFactory(1 << 16, repository); diskFileItemFactory.setFileCleaningTracker(fileCleaningTracker); - blockedURLSubstrings = new ArrayList<>(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - DecodeServlet.class.getResourceAsStream("/private/uri-block-substrings.txt"), UTF8))) { - String line; - while ((line = reader.readLine()) != null) { - blockedURLSubstrings.add(line); - } + try { + blockedURLSubstrings = + Resources.readLines(Resources.getResource("/private/uri-block-substrings.txt"), Charsets.UTF_8); } catch (IOException ioe) { throw new ServletException(ioe); } @@ -194,8 +189,8 @@ public final class DecodeServlet extends HttpServlet { connection.setAllowUserInteraction(false); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); - connection.setRequestProperty("User-Agent", "zxing.org"); - connection.setRequestProperty("Connection", "close"); + connection.setRequestProperty(HttpHeaders.USER_AGENT, "zxing.org"); + connection.setRequestProperty(HttpHeaders.CONNECTION, "close"); try { @@ -222,7 +217,7 @@ public final class DecodeServlet extends HttpServlet { response.sendRedirect("badurl.jspx"); return; } - if (connection.getHeaderFieldInt("Content-Length", 0) > MAX_IMAGE_SIZE) { + if (connection.getHeaderFieldInt(HttpHeaders.CONTENT_LENGTH, 0) > MAX_IMAGE_SIZE) { log.info("Too large"); response.sendRedirect("badimage.jspx"); return; @@ -314,7 +309,7 @@ public final class DecodeServlet extends HttpServlet { } if (image.getHeight() <= 1 || image.getWidth() <= 1 || image.getHeight() * image.getWidth() > MAX_PIXELS) { - log.info("Dimensions too large: " + image.getWidth() + 'x' + image.getHeight()); + log.info("Dimensions out of bounds: " + image.getWidth() + 'x' + image.getHeight()); response.sendRedirect("badimage.jspx"); return; } @@ -328,7 +323,7 @@ public final class DecodeServlet extends HttpServlet { LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source)); - Collection results = new ArrayList<>(1); + Collection results = Lists.newArrayListWithCapacity(1); try { @@ -396,9 +391,9 @@ public final class DecodeServlet extends HttpServlet { String fullParameter = request.getParameter("full"); boolean minimalOutput = fullParameter != null && !Boolean.parseBoolean(fullParameter); if (minimalOutput) { - response.setContentType("text/plain"); - response.setCharacterEncoding("UTF8"); - try (Writer out = new OutputStreamWriter(response.getOutputStream(), UTF8)) { + response.setContentType(MediaType.PLAIN_TEXT_UTF_8.toString()); + response.setCharacterEncoding(Charsets.UTF_8.name()); + try (Writer out = new OutputStreamWriter(response.getOutputStream(), Charsets.UTF_8)) { for (Result result : results) { out.write(result.getText()); out.write('\n');