Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
25   89   15   4.17
16   75   0.6   6
6     2.5  
1    
 
 
  GzipResponseWrapper       Line # 10 25 15 0% 0.0
 
No Tests
 
1    package com.atlassian.core.filters.gzip;
2   
3    import javax.servlet.ServletOutputStream;
4    import javax.servlet.http.HttpServletResponse;
5    import javax.servlet.http.HttpServletResponseWrapper;
6    import java.io.IOException;
7    import java.io.OutputStreamWriter;
8    import java.io.PrintWriter;
9   
 
10    public class GzipResponseWrapper extends HttpServletResponseWrapper
11    {
12    protected HttpServletResponse origResponse = null;
13    protected ServletOutputStream stream = null;
14    protected PrintWriter writer = null;
15    private final String encoding;
16   
 
17  0 toggle public GzipResponseWrapper(HttpServletResponse response, String encoding)
18    {
19  0 super(response);
20  0 origResponse = response;
21  0 this.encoding = encoding;
22    }
23   
 
24  0 toggle protected ServletOutputStream createOutputStream() throws IOException
25    {
26  0 return (new GzipResponseStream(origResponse));
27    }
28   
 
29  0 toggle public void finishResponse()
30    {
31  0 try
32    {
33  0 if (writer != null)
34    {
35  0 writer.close();
36    }
37    else
38    {
39  0 if (stream != null)
40    {
41  0 stream.close();
42    }
43    }
44    }
45    catch (IOException e)
46    {
47    }
48    }
49   
 
50  0 toggle public void flushBuffer() throws IOException
51    {
52  0 if (stream != null)
53  0 stream.flush();
54  0 if (writer != null)
55  0 writer.flush();
56    }
57   
 
58  0 toggle public ServletOutputStream getOutputStream() throws IOException
59    {
60  0 if (writer != null)
61    {
62  0 throw new IllegalStateException("getWriter() has already been called!");
63    }
64   
65  0 if (stream == null)
66  0 stream = createOutputStream();
67   
68  0 return (stream);
69    }
70   
 
71  0 toggle public PrintWriter getWriter() throws IOException
72    {
73  0 if (writer != null)
74    {
75  0 return (writer);
76    }
77   
78  0 if (stream != null)
79    {
80  0 throw new IllegalStateException("getOutputStream() has already been called!");
81    }
82   
83  0 stream = createOutputStream();
84   
85    //note - encoding should have beens set by the constructor
86  0 writer = new PrintWriter(new OutputStreamWriter(stream, encoding));
87  0 return (writer);
88    }
89    }