Java: Gzip string to output string

岁酱吖の 提交于 2019-12-24 07:38:03

问题


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:


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.



来源:https://stackoverflow.com/questions/2103855/java-gzip-string-to-output-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!