/** * Write the image using a specified write param */ protected void write(BufferedImage image) throws IOException { if (image == null) { return; } byte[] bytes = outputter.toBytes(image); if (minLength > bytes.length) { minBytes = bytes; minLength = minBytes.length; reductionPct = ((response.getContentLength() - minLength) * 100) / response.getContentLength(); } }
/** * Write the image using a specified write param */ protected void write(BufferedImage image) throws IOException { if (image == null) { return; } byte[] bytes = outputter.toBytes(image); if (minLength > bytes.length) { minBytes = bytes; minLength = minBytes.length; reductionPct = ((response.getContentLength() - minLength) * 100) / response.getContentLength(); } }
/** * Write the image using a specified write param */ protected void write(BufferedImage image) throws IOException { if (image == null) { return; } byte[] bytes = outputter.toBytes(image); if (minLength > bytes.length) { minBytes = bytes; minLength = minBytes.length; reductionPct = ((response.getContentLength() - minLength) * 100) / response.getContentLength(); } }
public BaseOptimizer(OptimizerConfig config, HttpResponseBuilder response, JpegImageUtils.JpegImageParams sourceImageParams) { this.config = config; this.response = response; this.minLength = response.getContentLength(); this.sourceImageParams = sourceImageParams; this.outputter = getOutputter(); }
public BaseOptimizer(OptimizerConfig config, HttpResponseBuilder response) { this.config = config; this.response = response; this.minLength = response.getContentLength(); this.outputter = getOutputter(); }
public BaseOptimizer(OptimizerConfig config, HttpResponseBuilder response) { this.config = config; this.response = response; this.minLength = response.getContentLength(); this.outputter = getOutputter(); }
public void rewrite(BufferedImage image) throws IOException { if (outputter == null) { return; } long time = System.currentTimeMillis(); rewriteImpl(image); time = System.currentTimeMillis() - time; if (minBytes != null && minBytes.length != 0) { StringBuilder rewriteMsg = new StringBuilder(24); rewriteMsg.append("c=").append( ((minBytes.length * 100) / response.getContentLength())); if (!getOutputContentType().equals(getOriginalContentType())) { rewriteMsg.append(";o=").append(getOriginalContentType()); } rewriteMsg.append(";t=").append(time); // Removing the original 'Etag' header as we have updated the content. response.removeHeader("ETag"); response .setHeader("Content-Type", getOutputContentType()) .setHeader("X-Shindig-Rewrite", rewriteMsg.toString()) .setResponse(minBytes); } }
public void rewrite(BufferedImage image) throws IOException { if (outputter == null) { return; } long time = System.currentTimeMillis(); rewriteImpl(image); time = System.currentTimeMillis() - time; if (minBytes != null && minBytes.length != 0) { StringBuilder rewriteMsg = new StringBuilder(24); rewriteMsg.append("c=").append( ((minBytes.length * 100) / response.getContentLength())); if (!getOutputContentType().equals(getOriginalContentType())) { rewriteMsg.append(";o=").append(getOriginalContentType()); } rewriteMsg.append(";t=").append(time); response.clearAllHeaders() .setHeader("Content-Type", getOutputContentType()) .setHeader("X-Shindig-Rewrite", rewriteMsg.toString()) .setResponse(minBytes); } }
public void rewrite(BufferedImage image) throws IOException { if (outputter == null) { return; } long time = System.currentTimeMillis(); rewriteImpl(image); time = System.currentTimeMillis() - time; if (minBytes != null && minBytes.length != 0) { StringBuilder rewriteMsg = new StringBuilder(24); rewriteMsg.append("c=").append( ((minBytes.length * 100) / response.getContentLength())); if (!getOutputContentType().equals(getOriginalContentType())) { rewriteMsg.append(";o=").append(getOriginalContentType()); } rewriteMsg.append(";t=").append(time); response.clearAllHeaders() .setHeader("Content-Type", getOutputContentType()) .setHeader("X-Shindig-Rewrite", rewriteMsg.toString()) .setResponse(minBytes); } }
@Test public void testRewriteValidImageWithInvalidMimeAndFileExtn() throws Exception { byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png"); HttpResponseBuilder response = getImageResponse(CONTENT_TYPE_BOGUS, bytes); int originalContentLength = response.getContentLength(); rewriter.rewrite(new HttpRequest(Uri.parse("some.junk")), response, null); assertEquals(HttpResponse.SC_OK, response.getHttpStatusCode()); assertEquals(response.getContentLength(), originalContentLength); }
@Test public void testRewriteValidImageWithValidMimeAndExtn() throws Exception { byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png"); HttpResponseBuilder response = getImageResponse(CONTENT_TYPE_PNG, bytes); int originalContentLength = response.getContentLength(); rewriter.rewrite(new HttpRequest(Uri.parse("some.png")), response); assertEquals(HttpResponse.SC_OK, response.getHttpStatusCode()); assertTrue(response.getContentLength() < originalContentLength); }
@Test public void testRewriteValidImageWithInvalidMimeAndFileExtn() throws Exception { byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png"); HttpResponseBuilder response = getImageResponse(CONTENT_TYPE_BOGUS, bytes); int originalContentLength = response.getContentLength(); rewriter.rewrite(new HttpRequest(Uri.parse("some.junk")), response); assertEquals(HttpResponse.SC_OK, response.getHttpStatusCode()); assertEquals(response.getContentLength(), originalContentLength); }
@Test public void testRewriteValidImageWithValidMimeAndExtn() throws Exception { byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png"); HttpResponseBuilder response = getImageResponse(CONTENT_TYPE_PNG, bytes); int originalContentLength = response.getContentLength(); rewriter.rewrite(new HttpRequest(Uri.parse("some.png")), response, null); assertEquals(HttpResponse.SC_OK, response.getHttpStatusCode()); assertTrue(response.getContentLength() < originalContentLength); }
@Test public void testRewriteValidImageWithValidMimeAndExtn() throws Exception { byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png"); HttpResponseBuilder response = getImageResponse(CONTENT_TYPE_PNG, bytes); int originalContentLength = response.getContentLength(); rewriter.rewrite(new HttpRequest(Uri.parse("some.png")), response, null); assertEquals(HttpResponse.SC_OK, response.getHttpStatusCode()); assertTrue(response.getContentLength() < originalContentLength); }
@Test public void testRewriteValidImageWithInvalidMimeAndFileExtn() throws Exception { byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png"); HttpResponseBuilder response = getImageResponse(CONTENT_TYPE_BOGUS, bytes); int originalContentLength = response.getContentLength(); rewriter.rewrite(new HttpRequest(Uri.parse("some.junk")), response, null); assertEquals(HttpResponse.SC_OK, response.getHttpStatusCode()); assertEquals(response.getContentLength(), originalContentLength); }
if (response.getContentLength() < config.getMinThresholdBytes()) { return;
if (response.getContentLength() < config.getMinThresholdBytes()) { return;
if (response.getContentLength() < config.getMinThresholdBytes()) { return false;