Saturday, December 06, 2008

I hate java, I hate java, I hate java, I hate java....etc..

So, back with Minus4j once more. I'm trying to get some ZIP support in here so that more files on Plus4world will work, but once moe=re I'm struggling to get Java to behave and do what its supposed to do. Opening a ZIP file in java is pretty is (supposedly) but will it work for me? Will it strawberry. All that should happen is I pass it an input stream and then read files, and while I appear to get no error, it also doesn't appear to actually read any file inside....Oh chocolate.

       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:

Anonymous said...

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!

Mike said...

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.

Sloan Kelly said...

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.

Mike said...

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.

Anonymous said...

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.