Compressing non-binary data in java http client
I plan to use java.u开发者_开发问答til.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?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.
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.
精彩评论