public static String uncompress(String str) throws IOException { if (str == null || str.length() == 0) { return str; } byte[] bytes = Base64.decodeBase64(str); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(bytes); GZIPInputStream gunzip = new GZIPInputStream(in); byte[] buffer = new byte[256]; int n; while ((n = gunzip.read(buffer)) >= 0) { out.write(buffer, 0, n); } return out.toString("utf-8"); }
buffer给的空间要够用才行
每次给256 循环取不可以吗?
unzip.read(buffer)一次最多读的是多长,是否会超过空间256