How to decompress gzip data?

I have a byte array and I want to decompress this byte array. When I run below code it gives;

java.util.zip.ZipException: Not in GZIP format

I get this byte array from a soap webservice. When I call this webservice from soap UI it returns;

<size>491520</size>
<studentData>
    <dataContent>Uy0xMDAwMF90MTAwMDAtVXNlciBTZWN1cml0eSBB........</dataContent>
</studentData>

Is there a problem with data coming from web service or my decompress method?

public static byte[] decompress(final byte[] input) throws Exception{

    try (ByteArrayInputStream bin = new ByteArrayInputStream(input);
            GZIPInputStream gzipper = new GZIPInputStream(bin)) {
        byte[] buffer = new byte[1024];
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        int len;
        while ((len = gzipper.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }

        gzipper.close();
        out.close();
        return out.toByteArray();
    }
}

EDIT: I decoded base64 and write it to a file called "test.gzip". Now I can extract this file with 7zip and I can see all student files without any problem.

String encoded = Base64.getEncoder().encodeToString(studentData.getDataContent());
byte[] decoded = Base64.getDecoder().decode(encoded);

FileOutputStream fos = new FileOutputStream("test.gzip");
fos.write(decoded);
fos.close();

But when I try to decompress this decoded file it still gives same error;

decompress(decoded);
链接地址: http://www.djcxy.com/p/92424.html

上一篇: 服务器和客户端上的简化WCF配置

下一篇: 如何解压缩gzip数据?