public static byte[] decompressGzipToBytes(String file) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
FileInputStream in = new FileInputStream(file);
try (GZIPInputStream gis = new GZIPInputStream(in)) {
// copy GZIPInputStream to ByteArrayOutputStream
byte[] buffer = new byte[1024];
int len;
while ((len = gis.read(buffer)) > 0) {
output.write(buffer, 0, len);
System.out.println(buffer);
}
}
return output.toByteArray();
}
The above code doesn't properly read a Gzip file into bytes. I get characters like '[B@6d6f6e28' instead. But, if I use a BufferReader for text files, then it behaves as expected.
What I am doing wrong?