0

I am working with byte arrays in Java 1.7. I am using java.util.zip's Inflater and Deflater classes to compress the data. I have to interface with data generated by Python code.

Does Python have the capability to compress data that can be uncompressed by Java's Inflater class, and the capability to decompress data that has been compressed by Java's Deflater class?

Brian
  • 1,726
  • 2
  • 24
  • 62
  • Additional reading, [are zlib on python and deflater on java compatible](https://stackoverflow.com/questions/2424945/are-zlib-compress-on-python-and-deflater-deflate-on-java-android-compatible). – Reti43 Apr 06 '16 at 14:21

2 Answers2

2

If you meant if there is something in python to handle ZIP format, there is. It is the module zipfile. Python comes with all batteries included.

C Panda
  • 3,297
  • 2
  • 11
  • 11
2

Commonly, these use GZIP. It would appear java.util.zip uses ZLIB and has support for GZIP.

https://docs.python.org/2/library/gzip.html Is a python library that uses ZLIB and GZIP

Christopher Schneider
  • 3,745
  • 2
  • 24
  • 38
  • That looks good, but it seems to deal with zip files. Is there a module for dealing with zipping internal objects? – Brian Apr 06 '16 at 15:21
  • If we're talking objects, that's a completely different animal than just compressing data. The best way to tackle something like that would be to convert it to XML (In Java, use JAXB. In Python, I'm not sure) and then compress the XML, if desired. The class structure should also be the same with getters/setters. – Christopher Schneider Apr 06 '16 at 15:26
  • In Java, I am compressing a byte array, and sending it across a network via UDP. The message needs a byte array, which is what java.util.zip Deflater gives me. – Brian Apr 06 '16 at 15:40
  • Right... So you'd convert to an XML string, compress the string, then send that data. When you decompress on the Python side, you'd have the XML string back and could map that to an object. Keep in mind that you could lose data sending it over UDP though. – Christopher Schneider Apr 07 '16 at 20:21