Compressing and decompressing streams

前端 未结 1 1469
抹茶落季
抹茶落季 2021-01-18 01:33

I found this article about simple proxy server implemented in JAVA:

http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm

The code simply g

相关标签:
1条回答
  • 2021-01-18 02:12

    Read the javadoc of these streams : http://download.oracle.com/javase/6/docs/api/java/util/zip/GZIPInputStream.html and http://download.oracle.com/javase/6/docs/api/java/util/zip/GZIPOutputStream.html.

    GZIPOutputStream compresses the bytes you write into it before sending them to the wrapped output stream. GZIPInputStream reads compressed bytes from the wrapped stream and returns uncompressed bytes.

    So, if you want to send compressed bytes to anyone, you must write to a GZIPOutputStream. But of course, this will only work if the receiving end knows it and decompresses the bytes it receives.

    Similarly, if you want to read compressed bytes, you need to read them from a GZIPInputSTream. But of course, it'll only work if the bytes are indeed compressed using the same algorithm by the sending end.

    0 讨论(0)
提交回复
热议问题