gpt4 book ai didi

java - 无法使用 Apache MINA 压缩过滤器对通过 java.util.zip.Deflater 缩小的缓冲区进行充气

转载 作者:行者123 更新时间:2023-12-02 00:43:52 24 4
gpt4 key购买 nike

本次测试:

import java.util.zip.Deflater;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.filter.support.Zlib;
import org.junit.*;

public class ZlibTest {
private Deflater deflater = null;

private Zlib inflater = null;

@Before
public void setUp() throws Exception {
deflater = new Deflater(Deflater.BEST_COMPRESSION);
deflater.setStrategy(Deflater.DEFAULT_STRATEGY);
inflater = new Zlib(Zlib.COMPRESSION_MAX, Zlib.MODE_INFLATER);
}

@Test
public void testInflate() throws Exception {
byte[] compressed = new byte[14];
deflater.setInput(new byte[] {1});
deflater.finish();
int bytesCompressed = deflater.deflate(compressed);
IoBuffer compressedBuffer = IoBuffer.wrap(compressed, 0, bytesCompressed);
System.out.println(compressedBuffer);

IoBuffer byteUncompressed = inflater.inflate(compressedBuffer);
}
}

失败:

java.io.IOException: Unknown error. Error code : 1
at org.apache.mina.filter.support.Zlib.inflate(Zlib.java:136)
at ZlibTest.testInflate(ZlibTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

这里出了什么问题?

更新:如果我添加

        case JZlib.Z_STREAM_END:

Zlib.java 中的第 139 行,它解码得很好。

最佳答案

关于http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4255743 (著名的 13 年前的 bug - 如果是我的 child ,很快就会去高中),修复已在 Java 7 中提供(最后);确实有一个

public int deflate(byte[] b, int off, int len, int flush) {
if (b == null) {
throw new NullPointerException();
}
if (off < 0 || len < 0 || off > b.length - len) {
throw new ArrayIndexOutOfBoundsException();
}
synchronized (zsRef) {
ensureOpen();
if (flush == NO_FLUSH || flush == SYNC_FLUSH ||
flush == FULL_FLUSH)
return deflateBytes(zsRef.address(), b, off, len, flush);
throw new IllegalArgumentException();
}
}

添加到 Deflater 类的代码部分。因此,今天(2012 年),如果您只需要 java.util 的功能,您就可以继续使用该功能。

关于java - 无法使用 Apache MINA 压缩过滤器对通过 java.util.zip.Deflater 缩小的缓冲区进行充气,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5535783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com