Decompress GZip string in Java

前端 未结 3 2048
北海茫月
北海茫月 2021-02-07 12:40

I can find plenty of functions that let you decompress a GZip file, but how do I decompress a GZip string?

I\'m trying to parse a HTTP response where the response body i

3条回答
  •  渐次进展
    2021-02-07 13:16

    May be this helps :

    try (final GZIPInputStream gzipInput = new GZIPInputStream(new ByteArrayInputStream(compressedByteArray));
            final StringWriter stringWriter = new StringWriter()) {
            org.apache.commons.io.IOUtils.copy(gzipInput, stringWriter, "UTF_8");
            String decodedString = stringWriter.toString();
        } catch (IOException e) {
            throw new UncheckedIOException("Error while decompression!", e);
        }
    

提交回复
热议问题