Merge pull request #158 from jpinner/zlib_decoder_preset_dict_3_2
ZlibDecoder preset dictionary 3.2
This commit is contained in:
commit
e4fa180478
@ -32,6 +32,7 @@ import org.jboss.netty.util.internal.jzlib.ZStream;
|
|||||||
public class ZlibDecoder extends OneToOneDecoder {
|
public class ZlibDecoder extends OneToOneDecoder {
|
||||||
|
|
||||||
private final ZStream z = new ZStream();
|
private final ZStream z = new ZStream();
|
||||||
|
private byte[] dictionary;
|
||||||
private volatile boolean finished;
|
private volatile boolean finished;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,17 +73,13 @@ public class ZlibDecoder extends OneToOneDecoder {
|
|||||||
if (dictionary == null) {
|
if (dictionary == null) {
|
||||||
throw new NullPointerException("dictionary");
|
throw new NullPointerException("dictionary");
|
||||||
}
|
}
|
||||||
|
this.dictionary = dictionary;
|
||||||
|
|
||||||
synchronized (z) {
|
synchronized (z) {
|
||||||
int resultCode;
|
int resultCode;
|
||||||
resultCode = z.inflateInit(JZlib.W_ZLIB);
|
resultCode = z.inflateInit(JZlib.W_ZLIB);
|
||||||
if (resultCode != JZlib.Z_OK) {
|
if (resultCode != JZlib.Z_OK) {
|
||||||
ZlibUtil.fail(z, "initialization failure", resultCode);
|
ZlibUtil.fail(z, "initialization failure", resultCode);
|
||||||
} else {
|
|
||||||
resultCode = z.inflateSetDictionary(dictionary, dictionary.length);
|
|
||||||
if (resultCode != JZlib.Z_OK) {
|
|
||||||
ZlibUtil.fail(z, "failed to set the dictionary", resultCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,6 +128,16 @@ public class ZlibDecoder extends OneToOneDecoder {
|
|||||||
z.next_out_index = 0;
|
z.next_out_index = 0;
|
||||||
|
|
||||||
switch (resultCode) {
|
switch (resultCode) {
|
||||||
|
case JZlib.Z_NEED_DICT:
|
||||||
|
if (dictionary == null) {
|
||||||
|
ZlibUtil.fail(z, "decompression failure", resultCode);
|
||||||
|
} else {
|
||||||
|
resultCode = z.inflateSetDictionary(dictionary, dictionary.length);
|
||||||
|
if (resultCode != JZlib.Z_OK) {
|
||||||
|
ZlibUtil.fail(z, "failed to set the dictionary", resultCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case JZlib.Z_STREAM_END:
|
case JZlib.Z_STREAM_END:
|
||||||
finished = true; // Do not decode anymore.
|
finished = true; // Do not decode anymore.
|
||||||
z.inflateEnd();
|
z.inflateEnd();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user