Java: Gzip string to output string

2019-07-28 22:40发布

How do I take a string and use something 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.

1条回答
小情绪 Triste *
2楼-- · 2019-07-28 23:25

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.

查看更多
登录 后发表回答