From 70e0eba894bfe088868a4647cb71c8bdb2930162 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 7 Mar 2012 20:00:50 +0900 Subject: [PATCH] Replace SpdyHeaderBlockJZlibDecompressor with java.util.zip.Inflater-based one It should be fine because the Inflater-based one uses only JDK 1.5 API --- .../SpdyHeaderBlockJZlibDecompressor.java | 96 ------------------- .../spdy/SpdyHeaderBlockZlibDecompressor.java | 5 +- 2 files changed, 1 insertion(+), 100 deletions(-) delete mode 100644 codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibDecompressor.java diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibDecompressor.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibDecompressor.java deleted file mode 100644 index a177fea398..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibDecompressor.java +++ /dev/null @@ -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 io.netty.handler.codec.spdy; - -import io.netty.buffer.ChannelBuffer; -import io.netty.handler.codec.compression.CompressionException; -import io.netty.util.internal.jzlib.JZlib; -import io.netty.util.internal.jzlib.ZStream; - -import static io.netty.handler.codec.spdy.SpdyCodecUtil.*; - -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; - } -} diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecompressor.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecompressor.java index 192918a5e6..87f5ba09e9 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockZlibDecompressor.java @@ -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); } }