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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With