Unzip GZIP in String to String - Android File Input Output

Android examples for File Input Output:Zip File

Description

Unzip GZIP in String to String

Demo Code


//package com.java2s;
import android.util.Base64;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import java.util.zip.GZIPInputStream;

public class Main {
    public static String getUnzip(String zipCode) {
        byte[] unzipData = unzip(Base64.decode(zipCode, 0));
        String content = new String(unzipData);
        return content;
    }//from w  ww. ja v  a2 s.co  m

    public static byte[] unzip(byte[] zipData) {
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();

            ByteArrayInputStream inputstream = new ByteArrayInputStream(
                    zipData);
            GZIPInputStream v3_1 = new GZIPInputStream(inputstream);
            int count;
            byte dsata[] = new byte[1024];
            while ((count = v3_1.read(dsata, 0, 1024)) != -1) {
                os.write(dsata, 0, count);
            }
            v3_1.close();
            return os.toByteArray();
        } catch (Exception e) {
            return null;
        }

    }
}

Related Tutorials