How to get the compression ratio for a GZipped file ?

Posted by Enigma on Stack Overflow See other posts from Stack Overflow or by Enigma
Published on 2010-04-12T20:49:58Z Indexed on 2010/04/12 20:53 UTC
Read the original article Hit count: 243

Filed under:
|
|

Here is how I compressed the data:

<%@ page import="javax.servlet.jsp.*,java.io.*,java.util.zip.*" %>

<%
String encodings = request.getHeader("Accept-Encoding");
PrintWriter outWriter = null;

if ((encodings != null) && (encodings.indexOf("gzip") != -1)) {
  OutputStream outA = response.getOutputStream();
  outWriter = new PrintWriter(new GZIPOutputStream(outA), false);
  response.setHeader("Content-Encoding", "gzip");
  int a = response.getBufferSize();
  System.out.println("ZIPPED VERSION BF:"+a);
  } 
else {
  System.out.println("UN-ZIPPED VERSION");
  outWriter = new PrintWriter(response.getOutputStream(), false);
}

outWriter.println("<HTML><BODY>");

for(int i=0; i<1000; i++) {
  outWriter.println(" blah blah blah<br>");
}

outWriter.println("</BODY></HTML>");
outWriter.close();
%>

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp