wood burning stoves*
The moose likes I/O and Streams and the fly likes Problem with ZipInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with ZipInputStream" Watch "Problem with ZipInputStream" New topic
Author

Problem with ZipInputStream

Bhavik Shahm
Greenhorn

Joined: Apr 12, 2012
Posts: 3
I am trying to read a zip file having size approximately equal to 300 mb , which when unzipped comes to 4.5 gb

while executing i am getting below error:

Caused by: java.util.zip.ZipException: invalid entry size (expected 4294967295 but got 5230434248 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:376)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:148)




The file consist of approximately 9993030 records.

Below is the code snippet that i am running






The above code reads 9993023 lines of data after that it ends with the error message invalid entry size (expected 4294967295 but got 5230434248 bytes)

Unzipped the file and then read it using java was able to read all the records.

ZipInputStream internally use inflater class. After reading 9993023 line on next read the Inflater class read method returns 0 as read bytes because of which the EOF is set and we get the above error.

Ideally Inflater should return some bytes as still the records exists.

Is there and issue with the Inflater class of java and why is it not able to read the rest of the records.


Any help appreciated!!



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Bhavik Shahm wrote:[b]Caused by: java.util.zip.ZipException: invalid entry size (expected 4294967295 but got 5230434248 bytes)

4294967295 is 2^32 - 1. In other words, at 4GB the ZIP file fails. If I recall correctly, ZipFile and ZipInputStream were limited to this size up to Java 6. If I also recall correctly, this limited was removed in Java 7.

From Apache Commons Compress:
The traditional ZIP format is limited to archive sizes of four gibibyte (actually 232 - 1 bytes ≈ 4.3 GB) and 65635 entries, where each individual entry is limited to four gibibyte as well.

Besides the file size, the number of entries you have also exceeds the limits.

So you have two choices: upgrade to Java 7, or switch to Apache Commons Compress 1.3 or higher.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bhavik Shahm
Greenhorn

Joined: Apr 12, 2012
Posts: 3
Thanks for the reply.

The same thing when i am trying with below code snippet it is working

ZipFile zip=new ZipFile(new File("Y2012071.EDI.zip"));

Enumeration enum1=zip.entries();

while(enum1.hasMoreElements()){

ZipEntry ze=(ZipEntry)enum1.nextElement();

BufferedReader br = new BufferedReader(
new InputStreamReader(zip.getInputStream(ze)));
String line;
int linNum = 1;
while ((line = br.readLine()) != null) {
System.out.println(linNum);
linNum++;

}


Both getting InputStream from ZipFile or creating new ZipInputStream uses Inflater class for decompressing the data.

But i am getting error when i use ZipInputStream and not in case when i get inputstream using ZipFile.getInputStream.

Moreover it is reading the records and giving error before 15 records to EOF.

Will also check apache commons compress api

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Also, make sure the ZIP file is not corrupt by testing it in another application, like WinZip or 7-Zip.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with ZipInputStream
 
Similar Threads
Character Encoding
Is Zip or not?
Problem unzipping with ZipInputStream, containing filename with Swedish characters
Getting zip exception while decompressing a compressed file
UnZIPPing Exception