On server (C++), binary data is compressed using ZLib function:
compress2() and it's sent over to client (Java). On client side (Java), data should be decompressed using the following code snippet:
public static String unpack(byte[] packedBuffer) { InflaterInputStream inStream = new InflaterInputStream(new ByteArrayInputStream( packedBuffer); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); int readByte; try { while((readByte = inStream.read()) != -1) { outStream.write(readByte); } } catch(Exception e) { JMDCLog.logError(" unpacking buffer of size: " + packedBuffer.length); e.printStackTrace(); // ... the rest of the code follows } Problem is that when it tries to read in while loop it always throws:
java.util.zip.ZipException: invalid stored block lengths
Before I check for other possible causes can someone please tell me can I compress on one side with compress2 and decompress it on the other side using above code, so I can eliminate this as a problem? Also if someone has a possible clue about what might be wrong here (I know I didn't provide too much of of the code in here but projects are rather big.
Thanks.
packedBufferthe right size, for example?compress2(), checking the length and the data itself against what you receive in the Java code. If you're receiving the wrong data, you've got no hope of receiving it properly.