| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 15 |
Complexity Density: 0.6 |
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 17 |
0
|
public GzipResponseWrapper(HttpServletResponse response, String encoding)... |
| 18 |
|
{ |
| 19 |
0
|
super(response); |
| 20 |
0
|
origResponse = response; |
| 21 |
0
|
this.encoding = encoding; |
| 22 |
|
} |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 24 |
0
|
protected ServletOutputStream createOutputStream() throws IOException... |
| 25 |
|
{ |
| 26 |
0
|
return (new GzipResponseStream(origResponse)); |
| 27 |
|
} |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 29 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 50 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 58 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 71 |
0
|
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 |
|
|
| 86 |
0
|
writer = new PrintWriter(new OutputStreamWriter(stream, encoding)); |
| 87 |
0
|
return (writer); |
| 88 |
|
} |
| 89 |
|
} |