java先base64解码再Gzip解压缩

  |   0 评论   |   0 浏览
 1import java.io.ByteArrayInputStream;
 2import java.io.ByteArrayOutputStream;
 3import java.util.Base64;
 4import java.util.zip.GZIPInputStream;
 5import java.util.zip.GZIPOutputStream;
 6	
 7String compressStr="${data}"; //要解密的string
 8	    Base64.Decoder decoder = Base64.getDecoder();
 9	    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
10	    try {
11	        ByteArrayInputStream inputStream = new ByteArrayInputStream(decoder.decode(compressStr.getBytes("utf-8")));
12	        GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
13	        byte[] buffer = new byte[1024];
14	        for (int n = gzipInputStream.read(buffer); n != -1; n = gzipInputStream.read(buffer)) {
15	            outputStream.write(buffer, 0, n);
16	        }
17	        gzipInputStream.close();
18	        System.out.println(new String(outputStream.toByteArray(), "utf-8"));
19	        vars.put("url",new String(outputStream.toByteArray(), "utf-8"));
20	        return new String(outputStream.toByteArray(), "utf-8");   
21	    } catch (Exception e) {
22	        throw new RuntimeException("string deCompress exception", e);
23	    }
24

转载请注明出处,如有错误,请帮忙指正,谢谢!
标题:java先base64解码再Gzip解压缩
作者:走在人生的路上z
地址:http://www.17mark.com/articles/2020/08/14/1597376223695.html
此处应有打赏走在人生的路上z
走在人生的路上z