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

时间:2011-02-27 18:02:14

标签: java inputstream tar compression

嗨,伙计们, 测试我的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打开的缓冲区。  但是当我在链表中​​弹出一个元素然后尝试逐行读取时。我有这个例子..

SOmeOne有一个IDEa为什么我有例外???当我遍历tar.gz中的文件时,也许我错了somthin ?? 这样做我有代码:

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,所以它只包装了流。

1 个答案:

答案 0 :(得分:5)