从临时目录读取文件时,我看到EOFException异常。SQLite
以下是读取文件的代码。而且并不总是看到例外。考虑到 50K 个文件,它会出现 3 到 4 次。
public static byte[] decompressLzmaStream(InputStream inputStream, int size)
throws CompressorException, IOException {
if(size < 1) {
size = 1024 * 100;
}
try(LZMACompressorInputStream lzmaInputStream =
new LZMACompressorInputStream(inputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(size)) {
byte[] buffer = new byte[size];
int length;
while (-1 != (length = lzmaInputStream.read(buffer))) {
byteArrayOutputStream.write(buffer, 0, length);
}
byteArrayOutputStream.flush();
return byteArrayOutputStream.toByteArray();
}
}
我正在使用以下依赖项进行解压
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.20</version>
</dependency>
异常 while (-1 != (length = lzmaInputStream.read(buffer))) {
在行抛出。以下是例外。
java.io.EOFException: null at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)
at org.tukaani.xz.rangecoder.RangeDecoderFromStream.normalize(Unknown Source)
at org.tukaani.xz.rangecoder.RangeDecoder.decodeBit(Unknown Source)
at org.tukaani.xz.lzma.LZMADecoder.decode(Unknown Source)
at org.tukaani.xz.LZMAInputStream.read(Unknown Source)
at org.apache.commons.compress.compressors.lzma.
LZMACompressorInputStream.read(LZMACompressorInputStream.java:62)
at java.io.InputStream.read(InputStream.java:101)
任何人都对以下构造函数有任何想法commons-compress
。
// I am using this constructor of LZMACompressorInputStream
public LZMACompressorInputStream(InputStream inputStream) throws IOException {
this.in = new LZMAInputStream(this.countingStream = new CountingInputStream(inputStream), -1);
}
// This is added in later version of commons-compress, what is memoryLimitInKb
public LZMACompressorInputStream(InputStream inputStream, int memoryLimitInKb) throws IOException {
try {
this.in = new LZMAInputStream(this.countingStream = new CountingInputStream(inputStream), memoryLimitInKb);
} catch (MemoryLimitException var4) {
throw new org.apache.commons.compress.MemoryLimitException((long)var4.getMemoryNeeded(), var4.getMemoryLimit(), var4);
}
}
当我阅读LZMA 流时,我们需要将未压缩的大小传递给此处的构造函数 --> https://issues.apache.org/jira/browse/COMPRESS-286?page=com.atlassian.jira.plugin.system。 issuetabpanels%3Acomment-tabpanel&focusedCommentId=14109417#comment-14109417