I am porting a Python application to Android, and at some point this application should contact the web service, sending compressed data.
To do this, use the following method:
def stuff(self, data): "Convert into UTF-8 and compress." return zlib.compress(simplejson.dumps(data))
I use the following method to try to imitate this behavior in Android:
private String compressString(String stringToCompress) { Log.i(TAG, "Compressing String " + stringToCompress); byte[] input = stringToCompress.getBytes();
But the HTTP response from the server is incorrect, and I think this is because the compression result in Java does not match the result in Python.
I did a little test compressing "a" with both zlib.compress and deflate.
Python, zlib.compress () β x% 9CSJT% 02% 00% 01M% 00% A6
Android, Deflater.deflate β H% EF% BF% BDK% 04% 00% 00b% 00b
How do I compress data on Android to get the same zlib.compress () value in Python?
Any help, guide or guide is appreciated!
java python android zlib deflate
Edu zamora
source share