This might be a dumb problem but I'm really not able to figure it out. I'm making a SOAP request in SoapUI that retrieves me a GZIP compressed buffer for a certain file. My issue is that I'm not able to decompress the buffer obtained ( I'm not that experienced with java ). The only results that I obtained till now are some random 10-11 characters string ( [B@6d03e736 ) or errors like "not in GZIP format)
The buffer looks like this: "1f8b0800000000000000a58e4d0ac2400c85f78277e811f2e665329975bbae500f2022dd2978ff95715ae82cdcf9415efec823c6710247582d5965c32c65aab0f5fc0a5204c415855e7c190ef61b34710bcdc7486d2bab8a7a4910d022d5e107d211ed345f2f37a103da2ddb1f619ab8acefe7fdb1beb6394998c7dfbde3dcac3acf3f399f3eeae152012e010000"
I've looked in many similar threads and ran only into examples where someone gets a random string that gets compressed and then decompressed ( mostly trough GZIPInputStream/GZIPOutputStream ).
String stringBuffer = "buffer_from_above";
byte[] buffer = stringBuffer.getBytes(StandardCharsets.ISO_8859_1); // also tried UTF-8
System.out.println(decompress(buffer));
public static String decompress(final byte[] compressed) throws IOException {
final StringBuilder outStr = new StringBuilder();
if ((compressed == null) || (compressed.length == 0)) {
return "";
}
if (isCompressed(compressed)) {
final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(compressed));
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
String line;
while ((line = bufferedReader.readLine()) != null) {
outStr.append(line);
}
} else {
outStr.append(compressed);
}
return outStr.toString();
}
I would highly appreciate if someone is able to give me any tips or any advice for this matter. Thanks for the time spent and I wish you have a great day!
Decompress function stolen from this thread: compression and decompression of string data in java