Data compression in C#/J# and Java
Posted on 2004-10-28
Windows, Java 1.4, .NET Framework 1.1
I'm distributing dynamic content (always strings) by a .NET web page, and consume it by a Java client. I'd like to compress this content to speed up the time to delivery.
Referencing the J# library in the .NET project, I can utilize the Microsoft java.util.zip package. In my case, I'm - both client- and server-side - using the Java Inflater resp. Deflater objects. The Java resp. C# code is almost similar, and compression / decompression works fine for each platform.
I've made sure the strings which ought to be decompressed at the client exactly matches the strings compressed at the server (as aforementioned, decompressing them at the server does work).
In general and partly, the Java client is able to decompress the string compressed by the C# server.
But, the longer the string gets, the worse is the decompression success rate. I.e., the first 20 characters are decompressed 100% correct. 20% of the next 20 characters are not - or wrongly - decompressed, 30% of the next 20 characters, and so on.
I'd appreciate any well-directed hints.
1. I'm aware there is GZIPInputStream, etc. I'm not using it as I ran into problems with converting Java byte arrays to strings. In C# web applications, I can output strings or byte, but not sbyte (which is the equivalent of the Java byte type.
2. Also, the GZIPOutputStream complained it would need a dictionary (setDictionary()). I guess that's near where the solution is.
3. I'm also aware IIS 6.0 can be set up to deliver gzip'ed, dynamic content. I didn't want to choose this way as, AFAIK, any IIS website on this server would be concerned.