Decompress a String Using Inflater
Decompress a String Using Inflater.
Javadoc available at https://www.javatapas.com/docs/javatapas/string/DecompressString.html
public static String decompressString(String inStr) {
Inflater decompressor = new Inflater();
byte[] buf = new byte[1024];
byte[] inBytes = inStr.getBytes();
decompressor.setInput(inBytes);
ByteArrayOutputStream bos = new ByteArrayOutputStream(inBytes.length);
buf = new byte[1024];
while (!decompressor.finished()) {
try {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
} catch (DataFormatException e) {e.printStackTrace();}
}
try {bos.close();}
catch (IOException e) {e.printStackTrace();}
byte[] decompressedBytes = bos.toByteArray();
String decompressedStr = new String(decompressedBytes);
return decompressedStr;
}