Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when I use GZIPInputStream to read the gz file,It works but throws EOFException

I use GZIPInputStream to read the gz compessed file,It works but throw EOFException,how can I to resolve it,thanks.

in = new GZIPInputStream(new FileInputStream(file));
List<String> list = IOUtils.readLines(in, "UTF-8");
for (String item : list) {
    System.out.println(item);
}

The exception:

java.io.EOFException
  at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:268)
  at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:258) 
  at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:164) 
  at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79) 
  at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91) 
  at com.datamarket.job.controller.JobController.process(JobController.java:132)
like image 710
kaixi Avatar asked Oct 19 '25 05:10

kaixi


1 Answers

If you look at the stack trace you can see that the error is in readHeader. That usually means that the gzip file is corrupt. Perhaps you are reading something that is not in fact a valid gzip file? For example an empty file (as reading the first two bytes seems to fail with end of file)?

See if you can read the same file from the command line with the gzip command and double-check the file length. You could also test your code on a known good file, i.e. one that you create.

like image 154
ewramner Avatar answered Oct 21 '25 18:10

ewramner