java.io.EOFException: Unexpected end of ZLIB input stream

I

ilya

ZipInputStream in = new ZipInputStream(new FileInputStream(file));
in.getNextEntry();
OutputStream out = new FileOutputStream(outFile);
int mayRead = in.available();
byte[] buf = new byte[BUFFER_SIZE];
int len;
while ((len = in.read(buf, 0, Math.min(mayRead, BUFFER_SIZE)))
out.write(buf, 0, len);
}
in.closeEntry();
out.close();
in.close();

BUFFER_SIZE = 1024;

To unpack the zipped file I use the above method. On windows all works
fine. But on MAC I got the following error:
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:
223)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:
141)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:154)
at java.io.FilterInputStream.read(FilterInputStream.java:90)

How can I solve it?
 
A

Arne Vajhøj

ZipInputStream in = new ZipInputStream(new FileInputStream(file));
in.getNextEntry();
OutputStream out = new FileOutputStream(outFile);
int mayRead = in.available();
byte[] buf = new byte[BUFFER_SIZE];
int len;
while ((len = in.read(buf, 0, Math.min(mayRead, BUFFER_SIZE)))
out.write(buf, 0, len);
}
in.closeEntry();
out.close();
in.close();

BUFFER_SIZE = 1024;

To unpack the zipped file I use the above method. On windows all works
fine. But on MAC I got the following error:
java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:
223)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:
141)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:154)
at java.io.FilterInputStream.read(FilterInputStream.java:90)

How can I solve it?

The .available() method is not very reliable - I would avoid that.

Just read up to BUFFER_SIZE.

Have you verified that the zip file is actually readable on
MacOS X. The exception could be caused by file corruption - like
transferring the file as text instead of binary.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top