On my serverside, I used zlib python library to compress (zlib.compress()) a string and insret it into redis. In my redis, it shows:
x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]
If I read it from redis to python and use python zlib.decompress(), it works. It can print "Hello World".
How can I do it in java?
I tried this piece of code from Java 7 official documents.
String temp ="x\\xda\\xcbH\\xcd\\xc9\\xc9\\x07\\x00\\x06,\\x02\\x15";
byte[] output=temp.getBytes();
System.out.println(new String(output));
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0,output.length);
byte[] result = new byte[10000];
int resultLength = decompresser.inflate(result);
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength, "UTF-8");
System.out.println(outputString);
Java will throw error:
java.util.zip.DataFormatException: incorrect header check
What should I in order to decompress it? From other posts, I found people are using GZIPInputStream. Is there any performance difference?