Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GZIP Utility

 
Sagar Sharma
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do i need to code extra except setting of the Accept-Encoding Header to send HTML files in a GZIP format??

thanks in advance

sagar

 
Bob Moranski
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also need GZIPOutputStream. You can get it by
OutputStream out = new GZIPOutputStream(res.getOutputStream());
Then you can send it with ServletUtils class in Oreilly's servlet com package from www.servlets.com.
try{
ServletUtils.returnFile(file, out);
//file being the path to the specified file
}
catch(FileNotFoundException e){
throw new ServletException("No such file");
}
catch(IOException e){
throw new ServletException("Problem sending file...");
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic