For some reason I can't find a solid example online on how to do the following, so if anyone here can help that would great
I am transferring files over a socket in Java 6 and I would like to compress the data. I have looked into the ZIP Input Stream and although it seems good, I have had nothing but trouble getting it working. What I would rather do is:
- Read the uncompressed (normal) file into a byte[] array
- In memory, compress the byte[] into another byte[] that is zip-compressed
- transfer that new zipped byte[] over the normal OutputStream (no fancy deflater/inflater classes to deal with)
- On the other end, decompress the zip back to its original byte[] and write it to a new file.
I'd appreciate any examples on how to do those 4 steps :)
Here is why I'd rather not use the Zip IO Stream: Problems with using ZipOutputStream and ObjectOutputStream
You can use ZipInputStream available in Java. Here are the following classes you can use to accomplish what you want
ZipInputStream ZipOutputStream
If you have worked earlier on IO Streams, it is a cake walk. Let me know if you still cannot get it to work.