java 将base64编码的gzip数据解码并输出为文本 短示例
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Base64; import java.util.zip.GZIPInputStream;
public class Base64GzipDecoder {
public static void main(String[] args) throws IOException {
String base64GzipData = "H4sIAAAAAAAAAM3NzMlNzU3MjU3NTc3MrM0tKgBpJwIAAAAA";
byte[] decodedData = Base64.getDecoder().decode(base64GzipData);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(decodedData));
byte[] buffer = new byte[1024];
int length;
while ((length = gzipInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
String text = outputStream.toString("UTF-8");
System.out.println(text);
}
}
// 输出:Hello World!
原文地址: http://www.cveoy.top/t/topic/bO08 著作权归作者所有。请勿转载和采集!