View Javadoc

1   package com.atlassian.gzipfilter;
2   
3   import com.atlassian.gzipfilter.util.FlushableGZIPOutputStreamFactory;
4   
5   import java.io.IOException;
6   import java.util.zip.GZIPOutputStream;
7   import javax.servlet.ServletOutputStream;
8   import javax.servlet.http.HttpServletResponse;
9   
10  public final class GzipResponseStream extends ServletOutputStream
11  {
12      protected final GZIPOutputStream gzipstream;
13      protected final HttpServletResponse response;
14  
15      private final static int DEFAULT_BUFFER_SIZE_BYTES = 1024;
16  
17      public GzipResponseStream(HttpServletResponse response) throws IOException
18      {
19          super();
20          this.response = response;
21          gzipstream = FlushableGZIPOutputStreamFactory.makeFlushableGZIPOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE_BYTES);
22      }
23  
24      public void close() throws IOException
25      {
26          gzipstream.close();
27      }
28  
29      public void flush() throws IOException
30      {
31          gzipstream.flush();
32      }
33  
34      public void write(int b) throws IOException
35      {
36          gzipstream.write(b);
37      }
38  
39      public void write(byte b[]) throws IOException
40      {
41          this.write(b, 0, b.length);
42      }
43  
44      public void write(byte b[], int off, int len) throws IOException
45      {
46          gzipstream.write(b, off, len);
47      }
48  }