GZIPInputStream to String
2022-09-01 05:38:12
我正在尝试将HTTP响应的gzip压缩正文转换为明文。我已获取此响应的字节数组并将其转换为 ByteArrayInputStream。然后,我将其转换为GZIPInputStream。我现在想读取GZIPInputStream并将最终解压缩的HTTP响应正文存储为明文字符串。
此代码将最终解压缩的内容存储在 OutputStream 中,但我想将内容存储为字符串:
public static int sChunk = 8192;
ByteArrayInputStream bais = new ByteArrayInputStream(responseBytes);
GZIPInputStream gzis = new GZIPInputStream(bais);
byte[] buffer = new byte[sChunk];
int length;
while ((length = gzis.read(buffer, 0, sChunk)) != -1) {
out.write(buffer, 0, length);
}