16
16
package io .netty .handler .codec .spdy ;
17
17
18
18
import io .netty .buffer .ByteBuf ;
19
- import io .netty .buffer .Unpooled ;
19
+ import io .netty .buffer .ByteBufAllocator ;
20
20
21
21
import java .util .zip .DataFormatException ;
22
22
import java .util .zip .Inflater ;
@@ -41,7 +41,7 @@ void decode(ByteBuf encoded, SpdyHeadersFrame frame) throws Exception {
41
41
42
42
int numBytes ;
43
43
do {
44
- numBytes = decompress (frame );
44
+ numBytes = decompress (encoded . alloc (), frame );
45
45
} while (numBytes > 0 );
46
46
47
47
if (decompressor .getRemaining () != 0 ) {
@@ -65,8 +65,8 @@ private int setInput(ByteBuf compressed) {
65
65
return len ;
66
66
}
67
67
68
- private int decompress (SpdyHeadersFrame frame ) throws Exception {
69
- ensureBuffer ();
68
+ private int decompress (ByteBufAllocator alloc , SpdyHeadersFrame frame ) throws Exception {
69
+ ensureBuffer (alloc );
70
70
byte [] out = decompressed .array ();
71
71
int off = decompressed .arrayOffset () + decompressed .writerIndex ();
72
72
try {
@@ -87,23 +87,30 @@ private int decompress(SpdyHeadersFrame frame) throws Exception {
87
87
}
88
88
}
89
89
90
- private void ensureBuffer () {
90
+ private void ensureBuffer (ByteBufAllocator alloc ) {
91
91
if (decompressed == null ) {
92
- decompressed = Unpooled . buffer (DEFAULT_BUFFER_CAPACITY );
92
+ decompressed = alloc . heapBuffer (DEFAULT_BUFFER_CAPACITY );
93
93
}
94
94
decompressed .ensureWritable (1 );
95
95
}
96
96
97
97
@ Override
98
98
void reset () {
99
- decompressed = null ;
99
+ releaseBuffer () ;
100
100
super .reset ();
101
101
}
102
102
103
103
@ Override
104
104
public void end () {
105
- decompressed = null ;
105
+ releaseBuffer () ;
106
106
decompressor .end ();
107
107
super .end ();
108
108
}
109
+
110
+ private void releaseBuffer () {
111
+ if (decompressed != null ) {
112
+ decompressed .release ();
113
+ decompressed = null ;
114
+ }
115
+ }
109
116
}
0 commit comments