简体   繁体   中英

Java: Gzip string to output string

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM