One, gzip compression decompression
Package Java call JS;
Import Java.io.ByteArrayInputStream;
Import Java.io.ByteArrayOutputStream;
Import java.io.IOException;
Import Java.net.URLDecoder;
Import Java.net.URLEncoder;
Import Java.util.zip.GZIPInputStream;
Import Java.util.zip.GZIPOutputStream; public class Pako_gziputils {/** * @param str: normal String * @return Compressed String type: ³) °k,nic i£_ ' çe# c¦%âxhòjyiåö ' * @throws IOException */public static string compress (String str) throws IOException {if (str = = NULL | |
Str.length () = = 0) {return str;
} Bytearrayoutputstream out = new Bytearrayoutputstream ();
Gzipoutputstream gzip = new Gzipoutputstream (out);
Gzip.write (Str.getbytes ());
Gzip.close ();
Return out.tostring ("iso-8859-1");
}/** * @param str: type: ³) °k,nic i£_ ' çe# c¦%âxhòjyiåö ' * @return unzip the string to generate a normal string. * @throws IOException */public static string uncompress (String str) throws IOException {if (str = = NULL | | str.length () = = 0) {return str;
} Bytearrayoutputstream out = new Bytearrayoutputstream ();
Bytearrayinputstream in = new Bytearrayinputstream (str. getBytes ("iso-8859-1"));
Gzipinputstream gunzip = new Gzipinputstream (in);
byte[] buffer = new BYTE[256];
int n;
while ((n = gunzip.read (buffer)) >= 0) {out.write (buffer, 0, N);
}//ToString () uses the platform default encoding, or it can be explicitly specified as toString ("GBK") return out.tostring (); }/** * @param jsuristr: String type:%1F%C2%8B%08%00%00%00%00%00%00%03%C2%B3)%c2%b0k%2cni%03c%20i%c2%a3_%60%c3%87e %03%11%23%c2%82%0dc%c2%a6%25%c3%82xh%c3%b2jyi%c3%85%05%c3%96%60%1e%00%17%c2%8e%3dvf%00%00%00 * @return Generate a normal string * @throws IOException */public static String Uncompressuri (String jsuristr) throws IOException {string decod
Ejsuri=urldecoder.decode (Jsuristr, "UTF-8"); String GzipcompreSs=uncompress (Decodejsuri);
return gzipcompress; }/** * @param strdata: String type: normal String * @return Generate String type:%1F%C2%8B%08%00%00%00%00%00%00%03%C2%B3)%C2%B0K%2CN I%03c%20i%c2%a3_%60%c3%87e%03%11%23%c2%82%0dc%c2%a6%25%c3%82xh%c3%b2jyi%c3%85%05%c3%96%60%1e%00%17%c2%8e%3dvf
%00%00%00 * @throws IOException */public static string Compress2uri (String strdata) throws IOException {
String encodegzip=compress (strdata);
String Jsuristr=urlencoder.encode (Encodegzip, "UTF-8");
return jsuristr;
}
}
Two
Pako 1.0.3The decompression in JS:
A three-instance string.
var punzipstr= "%1f%c2%8b%08%00%00%00%00%00%00%03%c2%b3)%C2%B0K%2CNI%03C%20I%C2%A3_%60%C3%87E%03%11%23%C2%82%0DC %c2%a6%25%c3%82xh%c3%b2jyi%c3%85%05%c3%96%60%1e%00%17%c2%8e%3dvf%00%00%00 ";
This string is a uriencode string that needs to parse out the compressed code to extract it. (Because the compressed string, generally cannot be passed, you need to BASE64 generate strings, or generate encodeURI, etc., and then pass)