views:

91

answers:

2

I plan to use java.util.zip to compress http post data when sending it from a java client to the server(java servlet in this case). is this the best approach for reducing data load?
should I use gzip as the compression alg?

A: 

Possibly, Tag based data can be compressed fairly easily using a simple algorithm.

For every unique tag or attribute name, assign ID, replace tags with ID, store ID and tag name in separate file, then compress to zip.

Then simply replace your tag ID's with the tag names you get in the separate file after you decompress from zip.

(You don't HAVE to use two files, you can do it in the same file)

You can also do this method for individual 'Words' inside of the tags or attributes.

This takes a bit more time than just zipping it, but for medium to large files with a lot of repeated text, it saves a decent amount of data to be transfered.

I am not aware of what is defined in 'http post data', but if its just tags, a similar algorithm might work.

Meiscooldude
This is unlikely to yield better results than either GZip or Zip compression and is a lot more work.
Software Monkey
@Software Monkey This method works well for large amounts of repeated data. You of course would GZip or Zip the data after this operation. Excel's XSLX files use this method to compress the files a step further than zip.
Meiscooldude
@Meis: My point is that this is essentially what zip-type algorithms do, and they most likely do it better. So why bother?
Software Monkey
@Software Monkey: Ahh, I see what you're saying, in that case I completely agree with you.
Meiscooldude
A: 

Two standard compression Content-Encoding values for HTTP are gzip and deflate.

I had problems with IE 8 using deflate from a Java server and switched to gzip. I didn't have time to investigate further, but I had the impression at the time that either (a) more than the simple output of the Java DeflaterOutputStream was required, like some extra wrappering, or (b) there were options that needed to be set in order to ensure correct interoperability.

In my experience gzip compresses extremely well for text content and I have been working with Content-Type: gzip and a GZIPOutputStream with no problems against IE, FF and Chrome for a number of years.

Software Monkey