On server (C++), binary data is compressed using ZLib
function:
compress2()
and it\'s sent over to client (Java). On client side (
I think the problem is not with unpack method but in packedBuffer content. Unpack works fine
public static byte[] pack(String s) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream dout = new DeflaterOutputStream(out);
dout.write(s.getBytes());
dout.close();
return out.toByteArray();
}
public static void main(String[] args) throws Exception {
byte[] a = pack("123");
String s = unpack(a); // calls your unpack
System.out.println(s);
}
output
123
InflaterInputStream is expecting raw deflate data (RFC 1951), whereas compress2()
is producing zlib-wrapped deflate data (RFC 1950 around RFC 1951).
Inflater on the other hand does process zlib-wrapped data (unless you give it the nowrap
option). Go figure.