Lines 17-32
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.coyote.http11.filters; |
18 |
package org.apache.coyote.http11.filters; |
19 |
|
19 |
|
|
|
20 |
import org.apache.coyote.OutputBuffer; |
21 |
import org.apache.coyote.Response; |
22 |
import org.apache.coyote.http11.OutputFilter; |
23 |
import org.apache.tomcat.util.buf.ByteChunk; |
24 |
|
20 |
import java.io.IOException; |
25 |
import java.io.IOException; |
21 |
import java.io.OutputStream; |
26 |
import java.io.OutputStream; |
22 |
import java.util.zip.GZIPOutputStream; |
27 |
import java.util.zip.GZIPOutputStream; |
23 |
|
28 |
|
24 |
import org.apache.tomcat.util.buf.ByteChunk; |
29 |
import org.apache.coyote.http11.filters.FlushableGZIPOutputStream; |
25 |
|
30 |
|
26 |
import org.apache.coyote.OutputBuffer; |
|
|
27 |
import org.apache.coyote.Response; |
28 |
import org.apache.coyote.http11.OutputFilter; |
29 |
|
30 |
/** |
31 |
/** |
31 |
* Gzip output filter. |
32 |
* Gzip output filter. |
32 |
* |
33 |
* |
Lines 34-40
Link Here
|
34 |
*/ |
35 |
*/ |
35 |
public class GzipOutputFilter implements OutputFilter { |
36 |
public class GzipOutputFilter implements OutputFilter { |
36 |
|
37 |
|
37 |
|
|
|
38 |
// -------------------------------------------------------------- Constants |
38 |
// -------------------------------------------------------------- Constants |
39 |
|
39 |
|
40 |
|
40 |
|
Lines 42-47
Link Here
|
42 |
protected static final ByteChunk ENCODING = new ByteChunk(); |
42 |
protected static final ByteChunk ENCODING = new ByteChunk(); |
43 |
|
43 |
|
44 |
|
44 |
|
|
|
45 |
/** |
46 |
* Logger. |
47 |
*/ |
48 |
protected static org.apache.juli.logging.Log log |
49 |
= org.apache.juli.logging.LogFactory.getLog(GzipOutputFilter.class); |
50 |
|
51 |
|
45 |
// ----------------------------------------------------- Static Initializer |
52 |
// ----------------------------------------------------- Static Initializer |
46 |
|
53 |
|
47 |
|
54 |
|
Lines 82-88
Link Here
|
82 |
public int doWrite(ByteChunk chunk, Response res) |
89 |
public int doWrite(ByteChunk chunk, Response res) |
83 |
throws IOException { |
90 |
throws IOException { |
84 |
if (compressionStream == null) { |
91 |
if (compressionStream == null) { |
85 |
compressionStream = new GZIPOutputStream(fakeOutputStream); |
92 |
// compressionStream = new GZIPOutputStream(fakeOutputStream); |
|
|
93 |
compressionStream = new FlushableGZIPOutputStream(fakeOutputStream); |
86 |
} |
94 |
} |
87 |
compressionStream.write(chunk.getBytes(), chunk.getStart(), |
95 |
compressionStream.write(chunk.getBytes(), chunk.getStart(), |
88 |
chunk.getLength()); |
96 |
chunk.getLength()); |
Lines 92-97
Link Here
|
92 |
|
100 |
|
93 |
// --------------------------------------------------- OutputFilter Methods |
101 |
// --------------------------------------------------- OutputFilter Methods |
94 |
|
102 |
|
|
|
103 |
/** |
104 |
* Added to allow flushing to happen for the gzip'ed outputstream |
105 |
*/ |
106 |
public void flush() |
107 |
{ |
108 |
if (compressionStream != null) |
109 |
{ |
110 |
try |
111 |
{ |
112 |
if (log.isDebugEnabled()) |
113 |
{ |
114 |
log.debug("Flushing the compression stream!"); |
115 |
} |
116 |
compressionStream.flush(); |
117 |
} |
118 |
catch (IOException e) |
119 |
{ |
120 |
if (log.isDebugEnabled()) |
121 |
{ |
122 |
log.debug("Ignored exception while flushing gzip filter", e); |
123 |
} |
124 |
} |
125 |
} |
126 |
} |
95 |
|
127 |
|
96 |
/** |
128 |
/** |
97 |
* Some filters need additional parameters from the response. All the |
129 |
* Some filters need additional parameters from the response. All the |
Lines 117-123
Link Here
|
117 |
public long end() |
149 |
public long end() |
118 |
throws IOException { |
150 |
throws IOException { |
119 |
if (compressionStream == null) { |
151 |
if (compressionStream == null) { |
120 |
compressionStream = new GZIPOutputStream(fakeOutputStream); |
152 |
compressionStream = new FlushableGZIPOutputStream(fakeOutputStream); |
121 |
} |
153 |
} |
122 |
compressionStream.finish(); |
154 |
compressionStream.finish(); |
123 |
compressionStream.close(); |
155 |
compressionStream.close(); |