Esempio n. 1
0
 /** 对被压缩的字符串进行解压操作. */
 private String doInflater(String str) {
   try {
     byte[] buf = ZIP_CODER.base64ToByteArray(str);
     ByteArrayInputStream byteIn = new ByteArrayInputStream(buf);
     InflaterInputStream in = new InflaterInputStream(byteIn);
     ByteArrayOutputStream byteOut = new ByteArrayOutputStream(str.length() * 3 + 128);
     Utility.copyStream(in, byteOut);
     in.close();
     byte[] result = byteOut.toByteArray();
     return new String(result, "UTF-8");
   } catch (IOException ex) {
     // 这里不会出现IO异常因为全是内存操作
     throw new Error();
   }
 }
Esempio n. 2
0
 /** 对字符串进行压缩操作. */
 private String doDeflater(String str, BooleanRef ziped) {
   if (str.length() < this.minCompressSize) {
     ziped.value = false;
     return str;
   }
   try {
     ByteArrayOutputStream byteOut = new ByteArrayOutputStream(str.length() + 128);
     DeflaterOutputStream out = new DeflaterOutputStream(byteOut);
     byte[] buf = str.getBytes("UTF-8");
     out.write(buf);
     out.close();
     byte[] result = byteOut.toByteArray();
     ziped.value = true;
     return ZIP_CODER.byteArrayToBase64(result);
   } catch (IOException ex) {
     // 这里不会出现IO异常因为全是内存操作
     throw new Error();
   }
 }