private HttpServletResponse response; private GZIPOutputStream out; public GZIPResponseStream(HttpServletResponse response) throws IOException { this.response = response; this.out = new GZIPOutputStream(response.getOutputStream()); response.addHeader("Content-Encoding", "gzip"); } public void resetBuffer() { if (out != null && !response.isCommitted()) { response.setHeader("Content-Encoding", null); } out = null; } @Override public void write(int b) throws IOException { out.write(b); }