| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 12 |
Complexity Density: 0.44 |
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 20 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 30 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 48 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 57 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 66 |
0
|
public void write(byte[] b) throws IOException... |
| 67 |
|
{ |
| 68 |
0
|
write(b, 0, b.length); |
| 69 |
|
} |
| 70 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 71 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 80 |
0
|
public boolean closed()... |
| 81 |
|
{ |
| 82 |
0
|
return (this.closed); |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 85 |
0
|
public void reset()... |
| 86 |
|
{ |
| 87 |
|
|
| 88 |
|
} |
| 89 |
|
} |