Java:Gzip字符串输出字符串 [英] Java: Gzip string to output string

查看:206
本文介绍了Java:Gzip字符串输出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用字符串并使用 GZIPOutputStream gzip字符串,然后将压缩内容输出为字符串。

How do I take a string and use something like GZIPOutputStream to gzip the string and then output the zipped content as a string.

我的目的是通过HTTP将压缩内容作为post变量传输。

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

推荐答案

这些步骤实际上非常简单:

The steps are actually pretty simple:


  • 使用GZIPOutputStream将其写入ByteArrayOutputStream ...关闭GZIPOutputStream

  • 调用ByteArrayOutputStream.toBytes()获取字节数组

  • 在结果上使用Base64编码器

服务器的性能基本上与这些操作相反。

The server will perform essentially the reverse of these operations.

这篇关于Java:Gzip字符串输出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆