1、php服務(wù)壓縮數(shù)據(jù) 將字符串urlencode(因?yàn)閴嚎s之后的字符串會(huì)有非顯示字符):
x%DAKLJNIMK%CF%C8%CC%CA%CE%01%00%1E%B8%04%CF$str = "abcdefghijkl";$str = urlencode(gzcomPRess($str, 9));//為了字符串字符可見(jiàn)2、java解壓 由于PHP gzcompress使用ZLIB壓縮,因此java選擇對(duì)應(yīng)的壓縮算法解壓。 有一點(diǎn)是特別要注意的,一定要設(shè)置字符集,由于系統(tǒng)一般是UTF-8編碼。
public static void main(String[] args) throws IOException { String tmp = "x%DAKLJNIMK%CF%C8%CC%CA%CE%01%00%1E%B8%04%CF"; String decodeTmp = URLDecoder.decode(tmp,"ISO-8859-1"); System.out.println(decompress(decodeTmp)); }public static String decompress(String data) throws UnsupportedEncodingException { return decompress(data,"ISO-8859-1"); }public static String decompress(String data, String charset) throws UnsupportedEncodingException { byte[] bytes = data.getBytes(charset); byte[] output = new byte[0]; Inflater decompresser = new Inflater(); decompresser.reset(); decompresser.setInput(bytes); ByteArrayOutputStream o = new ByteArrayOutputStream(bytes.length); try { byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { e.printStackTrace(); } finally { try { o.close(); } catch (IOException e) { e.printStackTrace(); } } decompresser.end(); return new String(output); }新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注