开发者

Java: Gzip string to output string

开发者 https://www.devze.com 2022-12-17 04:21 出处:网络
How do I take a string and use somethi开发者_StackOverflow社区ng like GZIPOutputStream to gzip the string and then output the zipped content as a string.

How do I take a string and use somethi开发者_StackOverflow社区ng like GZIPOutputStream to gzip the string and then output the zipped content as a string.

My intention is to transfer the zipped content as a post variable through HTTP.


The steps are actually pretty simple:

  • Use the GZIPOutputStream to write it to a ByteArrayOutputStream... close the GZIPOutputStream
  • Call ByteArrayOutputStream.toBytes() to get the byte array
  • Use a Base64 encoder on the result

The server will perform essentially the reverse of these operations.

0

精彩评论

暂无评论...
验证码 换一张
取 消