unzip the contents on fly without creating physical zip file on the system

I have a zip file in byte[]. I need to extract the zipfile contents on fly without actually creating a zip file on the disk.

Is there any equivalent method like zipFile.entries() so that I can iterate the contents and get the ZipEntry. I would appreciate your help.

I tried the following code and was able to get only one file out of 3 files in the zip file(decodedZip).

public static void unZipContent(byte[] decodedZip) {

ZipInputStream in = null;

try {

ByteArrayInputStream bais = new ByteArrayInputStream(decodedZip);

in = new ZipInputStream(bais);

while (in.available() > 0) {

ZipEntry entry = in.getNextEntry();

if (entry != null) {

String outFilename = entry.getName();

System.out.println("filename is " + entry.getName());

}

}

catch(){}

}

[852 byte] By [michael_x11@yahoo.coma] at [2007-11-27 4:02:11]
# 1
What exception was thrown?
ejpa at 2007-7-12 9:06:53 > top of Java-index,Core,Core APIs...
# 2
No exception was thrown. I added 3 files to the zip file and was able to retrieve only one file name when I tried this code.
michael_x11@yahoo.coma at 2007-7-12 9:06:54 > top of Java-index,Core,Core APIs...
# 3
> catch(){}> No exception was thrown.With that code how can you possibly tell?
ejpa at 2007-7-12 9:06:54 > top of Java-index,Core,Core APIs...
# 4

> > catch(){}

> No exception was thrown.

>

> With that code how can you possibly tell?

Hey, if it compiles and runs it must be correct. Right?

You need to catch and rethrow the exception if you're handling exceptions at a higher level in your stack, or just throw it so you can at least see it :)

robpaynea at 2007-7-12 9:06:54 > top of Java-index,Core,Core APIs...
# 5

while (in.available() > 0) {

It is not good to organize input loops around available

See the API docs:

public ZipEntry getNextEntry()

throws IOException

/*

Reads the next ZIP file entry and positions the stream

at the beginning of the entry data.

Returns:

the next ZIP file entry, or null

if there are no more entries

*/

So this should be the loop:

while((entry = in.getNextEntry()) != null) {

//

}

BIJ001a at 2007-7-12 9:06:54 > top of Java-index,Core,Core APIs...
# 6
thank you very much, it worked.
michael_x11@yahoo.coma at 2007-7-12 9:06:54 > top of Java-index,Core,Core APIs...