集册 Java实例教程 用gzip解压缩字节数组

用gzip解压缩字节数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

381
用gzip解压缩字节数组
/* 
 来自 
*n o w    j a v a  . c o m*/


//package com.nowjava;

import java.io.ByteArrayInputStream;


import java.io.IOException;

import java.util.zip.GZIPInputStream;


public class Main {

    public static 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) {
        /*
         from NowJava.com 
展开阅读全文