General Development

ZLIB with Java? – jestermax

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
Has anyone ever used the Deflator/Inflator ZLIB classes in the java API? I'm thinking of playing with it. Just curious if anyone else has done anything with it..... man, we need more Java people here

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
Update:
I've gotten ZIP format compression working with java, so that's kind of neat but my search for Java ZLIB resources continues...

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
Have you seen jzlib? http://www.jcraft.com/jzlib/index.html

Its a pure java implement of zlib.

The download has a few examples of how to deflate/inflate streams.

------------------
Sam Washburn

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
i have indeed looked at it but i want to use the native api, since it has classes for it anyways. I've almost figured it out by looking at the api documentation though.
btw, did you mean that they gave examples using their library or the api?

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
So i figured out how the ZLIB classes of the java api work somewhat; the only example code i found was in the actual API javadocs. So i'm going to take it and convert it to input zip files and load objects (such as BufferedImages) from memory. The issue i have now is that in the example they give where they take a 14 character-long string and compress and decompress it; in the data buffer that holds the compressed data, they set it to a 100 byte long array.... is that actually meaningful? Is there a way of calculating how much space compressed data will take? or should i just set the buffer to the size of the original data and hope for the best?

------------------
Visit my portfolio (and check out my projects):
http://Jestermax.googlepages.com/

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
I'd go for 120% of the original size. Worse case would be an uncompressable file which would have the compression dictionary at the head. The extra 20% in the buffer should cover that. Its just a ballpark guess not an exact amount.

------------------
Sam Washburn

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
So i got the ZLIB stuff working, and the Zip archive stuff too. My plan is to create a manager that unzips an archive into memory and gives you access to the files. Basically a resource manager similar to Ogre or Irrlicht. Yes i know i should be reading the source code for it to get an idea, but....well i have no excuse.
Anyways, I was telling my dad about my plans for this. This is the same guy that told me he wanted me to write his spreadsheets in Java.... yeah. So he out of nowhere, asks me "does the computer have enough memory for all those files?". It made me think... is it actually useful to load large amounts of files into memory? Does anyone know how Ogre/Irrlicht does this? Ogre's resource manager searches a directory for stuff like images to use as textures and scripts for stuff such as materials. Does it just keep track of the filenames? or does it precache everything so it's fast to use?


EDIT/UPDATE: So i'm sorry this has turned into a personal blog, but once i get this working, anyone who wants the code can use it.
So I think i've discovered a decent case scenario of what this thing COULD be. I could just unzip the files as a temporary files that delete themselves when the VM is terminated. This way the archive would be unzipped and the files accessable like normal, but they would clear themselves after you're done with them. hmmmm, possibly i'm just speaking crazy-talk... it's kinda late and my mind is at the point where nothing really makes sense...so sorry for that

[This message has been edited by jestermax (edited March 25, 2007).]