<%@ page import="java.util.*, java.net.*, java.io.*" %>
<%
String url = request.getParameter("url");
long s,e;
if (url != null) {
URL noCompress = new URL(url);
HttpURLConnection huc =
(HttpURLConnection)noCompress.openConnection();
huc.setRequestProperty("user-agent","Mozilla(MSIE)");
s=Calendar.getInstance().getTimeInMillis();
huc.connect();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = huc.getInputStream();
while(is.read() != -1) {
baos.write((byte)is.read());
}
byte[] b1 = baos.toByteArray();
e=Calendar.getInstance().getTimeInMillis();
out.println(b1.length+" time="+(e-s));
URL compress = new URL(url);
HttpURLConnection hucCompress =
(HttpURLConnection)noCompress.openConnection();
hucCompress.setRequestProperty("accept-encoding","gzip");
hucCompress.setRequestProperty("user-agent","Mozilla(MSIE)");
s=Calendar.getInstance().getTimeInMillis();
hucCompress.connect();
ByteArrayOutputStream baosCompress =
new ByteArrayOutputStream();
InputStream isCompress = hucCompress.getInputStream();
while(isCompress.read() != -1) {
baosCompress.write((byte)isCompress.read());
}
byte[] b2 = baosCompress.toByteArray();
//request.setAttribute("t1", new Integer(b1.length));
//request.setAttribute("t2", new Integer(b2.length));
out.println("<br>");
e=Calendar.getInstance().getTimeInMillis();
out.println(b2.length+" time="+(e-s));
}
%>
