Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
27   89   12   3.38
8   74   0.44   8
8     1.5  
1    
 
 
  GzipResponseStream       Line # 12 27 12 0% 0.0
 
No Tests
 
1    package com.atlassian.core.filters.gzip;
2   
3    import com.opensymphony.module.sitemesh.util.FastByteArrayOutputStream;
4   
5    import java.io.ByteArrayOutputStream;
6    import java.io.IOException;
7    import java.util.zip.GZIPOutputStream;
8   
9    import javax.servlet.ServletOutputStream;
10    import javax.servlet.http.HttpServletResponse;
11   
 
12    public class GzipResponseStream extends ServletOutputStream
13    {
14    protected ByteArrayOutputStream baos = null;
15    protected GZIPOutputStream gzipstream = null;
16    protected boolean closed = false;
17    protected HttpServletResponse response = null;
18    protected ServletOutputStream output = null;
19   
 
20  0 toggle public GzipResponseStream(HttpServletResponse response) throws IOException
21    {
22  0 super();
23  0 closed = false;
24  0 this.response = response;
25  0 this.output = response.getOutputStream();
26  0 baos = new FastByteArrayOutputStream();
27  0 gzipstream = new GZIPOutputStream(baos);
28    }
29   
 
30  0 toggle public void close() throws IOException
31    {
32  0 if (closed)
33    {
34  0 throw new IOException("This output stream has already been closed");
35    }
36  0 gzipstream.finish();
37   
38  0 byte[] bytes = baos.toByteArray();
39   
40  0 response.addHeader("Content-Length", Integer.toString(bytes.length));
41  0 response.addHeader("Content-Encoding", "gzip");
42  0 output.write(bytes);
43  0 output.flush();
44  0 output.close();
45  0 closed = true;
46    }
47   
 
48  0 toggle public void flush() throws IOException
49    {
50  0 if (closed)
51    {
52  0 throw new IOException("Cannot flush a closed output stream");
53    }
54  0 gzipstream.flush();
55    }
56   
 
57  0 toggle public void write(int b) throws IOException
58    {
59  0 if (closed)
60    {
61  0 throw new IOException("Cannot write to a closed output stream");
62    }
63  0 gzipstream.write((byte) b);
64    }
65   
 
66  0 toggle public void write(byte[] b) throws IOException
67    {
68  0 write(b, 0, b.length);
69    }
70   
 
71  0 toggle public void write(byte[] b, int off, int len) throws IOException
72    {
73  0 if (closed)
74    {
75  0 throw new IOException("Cannot write to a closed output stream");
76    }
77  0 gzipstream.write(b, off, len);
78    }
79   
 
80  0 toggle public boolean closed()
81    {
82  0 return (this.closed);
83    }
84   
 
85  0 toggle public void reset()
86    {
87    //noop
88    }
89    }