Hi,
My
java program communicates with a VB Program using socket connection. I'm using Zlib.dll for compression at VB side & Inflator for decompression at java side. At java side if I define byte[] buff = new byte[256], then if I send a
string of size more than 256 bytes, althought compressed size less than 256, then on java side while decompressing, I get only first 256 bytesof the original string, thats true because buffer size is 256.
So to resolve this I tried to increase the buffer size, So now I'm getting decompressed size as 0.
Can nebody explain how to solve this problem.
Here is my decompression routine in Java:
public static String mydecompresser (byte[] b) {
// Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater();
decompressor.setInput(b);
// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos = new ByteArrayOutputStream(b.length);
// Decompress the data
byte[] buf = new byte[512];
while (!decompressor.finished()) {
try {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
catch (DataFormatException e) {e.printStackTrace();}
}
try {
bos.close();
} catch (IOException e) { e.printStackTrace();
}
// return the decompressed data
return bos.toString();
}
But it works for smaller string as 15 bytes sometimes more, but for longer strings it shows exception :
java.util.zip.DataFormatException:Incorrect Data Check
java.util.zip.Inflater.InflateBytes<NativeBytes>
Can anybody please sort this out, whats happening?
Is it because there are some characters in the received string which are not understood by java?