日度归档:2019年8月23日

android java gzip解压

    public String decompress(byte[] compressed) throws IOException {
        final int BUFFER_SIZE = 32;
        ByteArrayInputStream is = new ByteArrayInputStream(compressed);
        GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE);
        StringBuilder string = new StringBuilder();
        byte[] data = new byte[BUFFER_SIZE];
        int bytesRead;
        while ((bytesRead = gis.read(data)) != -1) {
            string.append(new String(data, 0, bytesRead));
        }
        gis.close();
        is.close();
        return string.toString();
    }

// 解压
           String cc = "H4sIAAAAAAAAA3s6ddlTVAQAXAODIhIAAAA=";
           try {
               this.decryptedText.setText(this.decompress(Base64.decode(cc.toCharArray())));
           } catch (IOException e) {
               e.printStackTrace();
           }