Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Decompression in java

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hey vinita,
Please do not cross post topics. Choose a single forum please.
Closing this. Refer to here for replies.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic