我从 Dockerfile 构建镜像:
FROM ubuntu
RUN apt-get update
然后将图像保存到我的本地计算机,我得到了这个文件,例如:
archive.ubuntu.com_ubuntu_dists_bionic_restricted_binary-amd64_Packages.lz4
我正在尝试在 Java lz4-java 中解压 ubuntu bionic lz4 文件:
LZ4Factory factory = LZ4Factory.fastestInstance();
byte[] encoded = Files.readAllBytes(Paths.get("<Path to file>"));
final int compressedLength = data.length;
LZ4Compressor compressor = factory.fastCompressor();
byte[] restored = new byte[compressedLength];
LZ4SafeDecompressor decompressor2 = factory.safeDecompressor();
decompressor2.decompress(data, 0, compressedLength, restored, 0);
我使用这个依赖项:
<dependency>
<groupId>org.lz4</groupId>
<artifactId>lz4-java</artifactId>
<version>1.5.1</version>
</dependency>
但我仍然遇到这个异常:
Exception in thread "main" net.jpountz.lz4.LZ4Exception: Error decoding offset 4 of input buffer
at net.jpountz.lz4.LZ4JNISafeDecompressor.decompress(LZ4JNISafeDecompressor.java:38)
at net.jpountz.lz4.LZ4SafeDecompressor.decompress(LZ4SafeDecompressor.java:74)
at org.whitesource.fs.Main.main(Main.java:89)
最佳答案
假设您的存档使用官方 LZ4 帧格式, 您可能更喜欢 this LZ4 Java version支持LZ4帧格式。
关于java - 用Java解压压缩的ubuntu lz4文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55047763/