@Test public void testUsedGunzipImplementationPerformance() throws IOException, AlreadyGzippedException, InterruptedException { byte[] gzip = getGzipFileAsBytes(); Collection headers = new ArrayList(); String[] header = new String[]{"Content-Encoding", "gzip"}; headers.add(header); PageInfo pageInfo = new PageInfo(200, "text/plain", headers, new ArrayList(), gzip, true, 0); long initialMemoryUsed = memoryUsed(); StopWatch stopWatch = new StopWatch(); int size = 0; long timeTaken = 0; long finalMemoryUsed = 0; long incrementalMemoryUsed = 0; byte[] ungzipped = null; for (int i = 0; i < 5; i++) { ungzipped = pageInfo.getUngzippedBody(); Thread.sleep(200); } stopWatch.getElapsedTime(); for (int i = 0; i < 50; i++) { ungzipped = pageInfo.getUngzippedBody(); } size = ungzipped.length; timeTaken = stopWatch.getElapsedTime() / 50; finalMemoryUsed = memoryUsed(); incrementalMemoryUsed = finalMemoryUsed - initialMemoryUsed; LOG.info("Average gunzip time: " + timeTaken + ". Memory used: " + incrementalMemoryUsed + ". Size: " + size); assertEquals(100000, size); assertTrue(timeTaken < 30); }
public byte[] getUngzippedBody() throws IOException { if (storeGzipped) { return ungzip(gzippedBody); } else { return ungzippedBody; } }
PageInfo implements Serializable { public byte[] getUngzippedBody() throws IOException { if (storeGzipped) { return ungzip(gzippedBody); } else { return ungzippedBody; } } }
PageInfo implements Serializable { public byte[] getUngzippedBody() throws IOException { if (storeGzipped) { return ungzip(gzippedBody); } else { return ungzippedBody; } } PageInfo(final int statusCode, final String contentType, final Collection headers, final Collection cookies,
                    final byte[] body, boolean storeGzipped, long timeToLiveSeconds); }
PageInfo implements Serializable { public byte[] getUngzippedBody() throws IOException { if (storeGzipped) { return ungzip(gzippedBody); } else { return ungzippedBody; } } PageInfo(final int statusCode, final String contentType, final Collection headers, final Collection cookies,
                    final byte[] body, boolean storeGzipped, long timeToLiveSeconds); static boolean isGzipped(byte[] candidate); String getContentType(); byte[] getGzippedBody(); List getResponseHeaders(); List getSerializableCookies(); int getStatusCode(); byte[] getUngzippedBody(); boolean hasGzippedBody(); boolean hasUngzippedBody(); boolean isOk(); Date getCreated(); long getTimeToLiveSeconds(); }
PageInfo implements Serializable { public byte[] getUngzippedBody() throws IOException { if (storeGzipped) { return ungzip(gzippedBody); } else { return ungzippedBody; } } PageInfo(final int statusCode, final String contentType, final Collection headers, final Collection cookies,
                    final byte[] body, boolean storeGzipped, long timeToLiveSeconds); static boolean isGzipped(byte[] candidate); String getContentType(); byte[] getGzippedBody(); List getResponseHeaders(); List getSerializableCookies(); int getStatusCode(); byte[] getUngzippedBody(); boolean hasGzippedBody(); boolean hasUngzippedBody(); boolean isOk(); Date getCreated(); long getTimeToLiveSeconds();  }