Does anybody know about any fast and free (as in beer) compression/decompression code for java ? It does not have to be very good at compression, just do the basic stuff. LZO would be a perfect choice, but it is GPL-ed, so I have not even checked if there exists a java version of it…
java.util.zip.GZIPInputStream and java.util.zip.GZIPOutputStream?
Check out jsr-200 [ http://www.jcp.org/en/jsr/detail?id=200 ]
there you can find among others:
http://jarg.sourceforge.net/
Anders - thanks for the links, but I’m have phrased myself not very clear - I’m looking for general compression algo, just implemented in java, not for something which compresses .class files.
Markus - yes, this is a fallback I’ll will use if nothing else will appear, but I’m seriously worried about speed of it and setup cost. I want to compress/decompress small pieces of data (0.5-8kb) very frequently, so setup cost should be minimal - at the same time, algorithm does not have to be very smart, as there will probably be not so many chances for advances compression in such small blocks.
What will your typical data look like? What amount of compression are you looking for?
It is easy enough to code simple run-length compression. Even adaptive Huffman codes would be manageable (I’ve done that in the past)
Art, make it work first, then worry about making it fast if you have to later. It might not be very slow after all.
Would this be, perhaps, for network games communication?
Cas
Yes, I’m thinking about game network communication. Reason why I would like to find a ready compression routine is exactly what you are talking about - to not have to worry about squeezing every bit out of message myself
BTW, if anybody would like a tester for his network code, I can apply - I have almost constant 15-20% packet loss on my connection, enough to make many of real time net games unplayable…
[quote]I have almost constant 15-20% packet loss on my connection, enough to make many of real time net games unplayable…
[/quote]
Heheh… and I consider Quake 3 unplayable with a ping over 10 and no loss :). Seriously twitch games over a net connection just don’t work for me… it takes all the fun out of the game when you are killed by shots that draw as complete misses, or your shots go through other players without counting. (These things happen all the time in Q3 - sometimes even on a LAN)
There will be some compression done by analog modems already. I don’t know what is reasonable to expect for small amounts of data like you are using. Compression is generally based on eliminating redundancy, or choosing more efficient code words like Huffman. You could capture some typical data to see if there are any trends in a histogram off code words. For example the values may all tend to be less than 15 because they represent changes between timestamps and things tend to not change by that much… so encoding two values per byte with a special escape sequence for larger values could give you near 50% compression. Look for trends in the data that you can exploit to see if there is a really simple solution.
You’ll have to implement it yourself, from the example code provided, but…If you can get hold of the last couple of issues of GameDeveloper (gdmag.com IIRC) there’s been a good series of articles about using “arithmetic coders” IIRC particularly for compressing network-protocol data (amongst other uses).
It might appear on gamasutra over the next couple of months, but it might not (I don’t know how they decide what to publish for free on the site, but obviously they can’t publish everything or no-one would read the mag. Or something like that…).
…or just Google for AC’s and find out what they’re about :). But AFAICS reading the articles in GD would be easier.
Thanks for the link - althrough I’m not a subscriber, code is free to download at
I’ll look into it and see if I’m able to understand anything without an article