GZipUtil { public static String unCompress(String str) { if (null == str || str.length() <= 0) { return str; } ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = null; GZIPInputStream gzip = null; try { in = new ByteArrayInputStream(str.getBytes("ISO-8859-1")); gzip = new GZIPInputStream(in); byte[] buffer = new byte[512]; int n = 0; while ((n = gzip.read(buffer)) >= 0) { out.write(buffer, 0, n); } return out.toString("utf-8"); } catch (Exception e) { LogUtils.e(e.getMessage(),e.fillInStackTrace()); } return null; }  static String compress(String str); static String unCompress(String str);  }
@Test public void unCompress() { String str = "{\"qrCodeData\":[{\"amount\":\"100004999975506010000000000\",\"chainId\":\"101\",\"from\":\"0xca4b151b0b100ae53c9d78dd136905e681622ee7\",\"functionType\":1004,\"gasLimit\":\"48988\",\"gasPrice\":\"499999750000\",\"nodeId\":\"0x411a6c3640b6cd13799e7d4ed286c95104e3a31fbb05d7ae0004463db648f26e93f7f5848ee9795fb4bbb5f83985afd63f750dc4cf48f53b0e84d26d6834c20c\",\"nodeName\":\"节点02\",\"nonce\":\"0\",\"stakingBlockNum\":\"\",\"to\":\"0x1000000000000000000000000000000000000002\",\"typ\":0}],\"qrCodeType\":0,\"timestamp\":1572590948}"; String zipStr = GZipUtil.compress(str); Log.d("GzipUtilsTest", "压缩后=========" + "长度" + zipStr.length() + "==========>" + "字节数组======" + zipStr.getBytes() + "----------->" +zipStr); String unzipStr = GZipUtil.unCompress(zipStr); Log.d("GzipUtilsTest", "解压缩=========" + "长度" + unzipStr.length() + "==========>" + "字节数组======" + unzipStr.getBytes() +"-------------->" +unzipStr); }