I have a key value storage which I have data stored. When I retrieve the value it is a JSON with a property "compressed_value", this value is a string and I don't know how to decompress or deserialize it.
I tried a lot of approaches, one of them try to cast the string to a byte[] using .getBytes() with different charsets, and using GZIPInputStream but I always get the error "java.util.zip.ZipException: Not in GZIP format".
The value es something like: "H4sIAAAAAAAA/wtOzC3ISVUoSa0oUSjJSCxRyFRITswrUUhJLU4tykzMyaxK1VFISczLVQQAkIb0eioAAAA=". When I paste it in a web like this one, it deserialize the value without problem.
Example code
public class Main {
public static void main(String[] args) throws IOException {
String compressedValue = "H4sIAAAAAAAA/wtOzC3ISVUoSa0oUSjJSCxRyFRITswrUUhJLU4tykzMyaxK1VFISczLVQQAkIb0eioAAAA=";
try {
final int BUFFER_SIZE = 32;
ByteArrayInputStream is = new ByteArrayInputStream(compressedValue.getBytes());
GZIPInputStream gis = new GZIPInputStream(is);
byte[] data = new byte[BUFFER_SIZE];
int bytesRead;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((bytesRead = gis.read(data)) != -1) {
baos.write(data, 0, bytesRead);
}
gis.close();
is.close();
System.out.println(baos.toString("UTF-8"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
}