[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>使用gzip对数据进行压缩、解压
我们在开发过程中,如果需要在客户端和服务器之间进行大量的数据传输操作,这种场景我们会优先考虑使用数据压缩的方式来减少传输的数据量,从而提高传输效率,以及减少客户端的运行内存等优势。
<>gzip简介
gzip是一种常用的压缩算法,它是若干种文件压缩程序的简称,通常指GNU计划的实现,此处的gzip代表GNU zip。
HTTP协议上的GZIP编码是一种用来改进WEB应用程序性能的技术。大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度。
<>Java中gzip压缩和解压实现
<>字节流压缩:
/** * 字节流gzip压缩 * @param data * @return */ public static byte[] gZip(byte[]
data) { byte[] b = null; try { ByteArrayInputStream in = new
ByteArrayInputStream(data); ByteArrayOutputStream out = new
ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out);
byte[] buffer = new byte[4096]; int n = 0; while((n = in.read(buffer, 0,
buffer.length)) > 0){ gzip.write(buffer, 0, n); } gzip.close(); in.close(); b =
out.toByteArray(); out.close(); } catch (Exception ex) { ex.printStackTrace();
} return b; }
<>字节流解压:
/** * gzip解压 * @param data * @return */ public static byte[] unGZip(byte[]
data){ // 创建一个新的输出流 ByteArrayOutputStream out = new ByteArrayOutputStream();
try { ByteArrayInputStream in = new ByteArrayInputStream(data); GZIPInputStream
gzip = new GZIPInputStream(in); byte[] buffer = new byte[4096]; int n = 0; //
将解压后的数据写入输出流 while ((n = gzip.read(buffer)) >= 0) { out.write(buffer, 0, n); }
in.close(); gzip.close(); out.close(); } catch (Exception e) {
e.printStackTrace(); } return out.toByteArray(); }