Created
August 26, 2017 12:09
-
-
Save patrickyin/687e52eb58209caf3e135125536ce58b to your computer and use it in GitHub Desktop.
decompress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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