Skip to content

Instantly share code, notes, and snippets.

@patrickyin
Created August 26, 2017 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickyin/687e52eb58209caf3e135125536ce58b to your computer and use it in GitHub Desktop.
Save patrickyin/687e52eb58209caf3e135125536ce58b to your computer and use it in GitHub Desktop.
decompress
private byte[] decompress(byte[] compressedData)
{
if(compressedData == null) return null;
Inflater inflater = new Inflater();
inflater.setInput(compressedData);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(compressedData.length);
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = 0;
try {
count = inflater.inflate(buffer);
} catch (DataFormatException e) {
e.printStackTrace();
return null;
}
outputStream.write(buffer, 0, count);
}
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
byte[] output = outputStream.toByteArray();
inflater.end();
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment