BufferedInputStream bis = new BufferedInputStream(_stream, 16384);
try
{
ZipInputStream in = new ZipInputStream(bis);
ZipEntry entry;
while( (entry = in.getNextEntry())!=null )
{
// process the ZIP
}
in.close();
}
So in the above code, it just never gets into the inner while loop and I've no idea why - so if you have any idea...let me know. I did think it was because it was coming over HTTP, so I read it all in and build a memory stream, but that doesn't seem to matter. On top of this, no one else seems to have this problem, so I can't find any answers on the net either..... *sigh*
5 comments:
Hey Mike,
IIRC, Java doesn't return values on assignment like C does. try breaking this up to 2 parts:
while( (entry = in.getNextEntry())!=null ) {
...;
}
to:
entry = in.getNextEntry();
while( entry !=null ) {
...;
entry = in.getNextEntry();
}
Good luck!
Actually, that was taken from another Java program on the web, and even if I split it up, it still doesn't work. entry is always null.
I thought I'd break out NetBeans and give your code a spin. I did this:
FileInputStream fis = new FileInputStream("/users/sloankelly/downloads/lunarlockout.zip");
BufferedInputStream bis = new BufferedInputStream(fis, 16384);
try
{
ZipInputStream in = new ZipInputStream(bis);
ZipEntry entry;
while( (entry = in.getNextEntry())!=null )
{
// process the ZIP
System.out.println(entry.getName());
}
in.close();
}
catch (Exception e)
{
}
And it worked. It displayed a list of the files inside the zip. So, I think maybe the stream isn't getting populated, and so it's not able to get the entries.
Thats what Im afraid of. The fact it needs an underlying FILE system, and won't work with HTTP file streams, or in memory streams for that matter.
I'll try it with a file stream, but thats of no use in the long term.
I too am having this issue on JDK6, WinXP. I've actually passed a proper file (on the filesystem) in to similar code and it doesn't read a single entry. Using ZipFile works but that doesn't sort my HTTP file stream requirement. No idea as to what the issue is.
As an aside:
"IIRC, Java doesn't return values on assignment like C does." - I don't believe that's right. It does return values as C does.
Post a Comment