Replace SpdyHeaderBlockJZlibDecompressor with java.util.zip.Inflater-based one
It should be fine because the Inflater-based one uses only JDK 1.5 API
This commit is contained in:
parent
0f680bc4dc
commit
4e6bf332a6
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.spdy;
|
||||
|
||||
import static org.jboss.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.handler.codec.compression.CompressionException;
|
||||
import org.jboss.netty.util.internal.jzlib.JZlib;
|
||||
import org.jboss.netty.util.internal.jzlib.ZStream;
|
||||
|
||||
class SpdyHeaderBlockJZlibDecompressor extends SpdyHeaderBlockDecompressor {
|
||||
|
||||
private final byte[] out = new byte[8192];
|
||||
private final ZStream z = new ZStream();
|
||||
|
||||
public SpdyHeaderBlockJZlibDecompressor() {
|
||||
int resultCode;
|
||||
resultCode = z.inflateInit(JZlib.W_ZLIB);
|
||||
if (resultCode != JZlib.Z_OK) {
|
||||
throw new CompressionException("ZStream initialization failure");
|
||||
}
|
||||
z.next_out = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInput(ChannelBuffer compressed) {
|
||||
byte[] in = new byte[compressed.readableBytes()];
|
||||
compressed.readBytes(in);
|
||||
z.next_in = in;
|
||||
z.next_in_index = 0;
|
||||
z.avail_in = in.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelBuffer decompressed) {
|
||||
z.next_out_index = 0;
|
||||
z.avail_out = out.length;
|
||||
|
||||
loop: for (;;) {
|
||||
// Decompress 'in' into 'out'
|
||||
int resultCode = z.inflate(JZlib.Z_SYNC_FLUSH);
|
||||
if (z.next_out_index > 0) {
|
||||
decompressed.writeBytes(out, 0, z.next_out_index);
|
||||
z.avail_out = out.length;
|
||||
}
|
||||
z.next_out_index = 0;
|
||||
|
||||
switch (resultCode) {
|
||||
case JZlib.Z_NEED_DICT:
|
||||
resultCode = z.inflateSetDictionary(SPDY_DICT, SPDY_DICT.length);
|
||||
if (resultCode != JZlib.Z_OK) {
|
||||
throw new CompressionException("failed to set the dictionary: " + resultCode);
|
||||
}
|
||||
break;
|
||||
case JZlib.Z_STREAM_END:
|
||||
// Do not decode anymore.
|
||||
z.inflateEnd();
|
||||
break loop;
|
||||
case JZlib.Z_OK:
|
||||
break;
|
||||
case JZlib.Z_BUF_ERROR:
|
||||
if (z.avail_in <= 0) {
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new CompressionException("decompression failure: " + resultCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (z.next_out_index > 0) {
|
||||
decompressed.writeBytes(out, 0, z.next_out_index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
z.inflateEnd();
|
||||
z.next_in = null;
|
||||
z.next_out = null;
|
||||
}
|
||||
}
|
@ -27,9 +27,6 @@ class SpdyHeaderBlockZlibDecompressor extends SpdyHeaderBlockDecompressor {
|
||||
private final byte[] out = new byte[8192];
|
||||
private final Inflater decompressor = new Inflater();
|
||||
|
||||
public SpdyHeaderBlockZlibDecompressor() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInput(ChannelBuffer compressed) {
|
||||
byte[] in = new byte[compressed.readableBytes()];
|
||||
@ -48,7 +45,7 @@ class SpdyHeaderBlockZlibDecompressor extends SpdyHeaderBlockDecompressor {
|
||||
decompressed.writeBytes(out, 0, numBytes);
|
||||
} catch (DataFormatException e) {
|
||||
throw new SpdyProtocolException(
|
||||
"Received invalid header block");
|
||||
"Received invalid header block", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user