Android实现zlib解压缩

    xiaoxiao2021-04-18  46

    清明时节雨纷纷。 在这四月的第一天;在这繁花似锦,万物复苏的月份,写下我这月的第一篇博文。 希望能给后面需要用到的小伙伴提供指引,少走弯路。 刚好项目需要做大量数据的查询处理,因此使用到了此解压缩技术,废话不多说, 直接上代码。

    //定义byte数组用来放置解压后的数据 byte[] output = new byte[0]; Inflater decompresser = new Inflater(); decompresser.reset(); //设置当前输入解压 decompresser.setInput(data, 0, data.length); ByteArrayOutputStream o = new ByteArrayOutputStream(data.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) { output = data; e.printStackTrace(); } finally { try { o.close(); } catch (IOException e) { e.printStackTrace(); } } decompresser.end(); return output;
    转载请注明原文地址: https://ju.6miu.com/read-674849.html

    最新回复(0)