java.io.EOFException:ZLIB 输入流意外结束

发布于 2024-10-19 14:32:17 字数 1710 浏览 4 评论 0原文

测试我的 tar.gz 提取工具,我发现抛出了异常:

java.io.EOFException: Unexpected end of ZLIB input stream
    at java.util.zip.InflaterInputStream.fill(Unknown Source)
    at java.util.zip.InflaterInputStream.read(Unknown Source)
    at java.util.zip.GZIPInputStream.read(Unknown Source)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at it.uniroma2.informatica.specialistica.IO.ScanCompressedFileUtil.main(ScanCompressedFileUtil.java:60

因此第 60 行的代码是:

BufferedReader bufLe= reader.remove();
try {
  while ( bufLe.ready() ){
    System.out.println(" "+bufLe.readLine());
  }
} catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}

调用 buffer.readLine() 时,抛出异常。当我打开 tar.gz 时,我保留了所有单个文件的流,就像 BuffReader 一样,然后我将它们放入一个 linkedList 中,然后我关闭了打开的文件 tar.gz 的缓冲区。

但是当我在链接列表中弹出一个元素然后尝试逐行读取时,我得到了执行。

为什么我有这个例外?当我迭代 tar.gz 中的文件时,也许我错了?

为此,我有代码:

TarInputStream is =  new TarInputStream(gzipInputStream);

TarEntry entryx = null;

try {
  while((entryx = is.getNextEntry()) != null) {
    InputStream tmpInx = new StreamingTarEntry(is,  entryx.getSize());
    // questo viene invocato perchè il file da lettere è un file txt
    manageTxtinsideTAR(tmpInx , buffer);
    // I add the stream to a linked list

STREAMINGTARENTRY 类扩展了 FilterInputStream,因此它仅包装流。

Testing my tar.gz extraction tool, I found thrown the exception:

java.io.EOFException: Unexpected end of ZLIB input stream
    at java.util.zip.InflaterInputStream.fill(Unknown Source)
    at java.util.zip.InflaterInputStream.read(Unknown Source)
    at java.util.zip.GZIPInputStream.read(Unknown Source)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at it.uniroma2.informatica.specialistica.IO.ScanCompressedFileUtil.main(ScanCompressedFileUtil.java:60

So the code at line 60 is:

BufferedReader bufLe= reader.remove();
try {
  while ( bufLe.ready() ){
    System.out.println(" "+bufLe.readLine());
  }
} catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}

where calling buffer.readLine(), throws the exception. When I open the tar.gz, I kept the stream of all single file, like BuffReader then I put them to a linkedList, and then i Closed the buffer of the file tar.gz opened.

But When I pop an element within the linked list and then try to read line by line, I have the execption.

Why do I have this exception? Maybe I am wrong somethinh when I iterate through the files within the tar.gz?

To doing so, I have the code:

TarInputStream is =  new TarInputStream(gzipInputStream);

TarEntry entryx = null;

try {
  while((entryx = is.getNextEntry()) != null) {
    InputStream tmpInx = new StreamingTarEntry(is,  entryx.getSize());
    // questo viene invocato perchè il file da lettere è un file txt
    manageTxtinsideTAR(tmpInx , buffer);
    // I add the stream to a linked list

THe class STREAMINGTARENTRY, extends FilterInputStream, so it's only wraps the stream.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文