Android Byte Array Zip compress(byte[] paramArrayOfByte)

Here you can find the source of compress(byte[] paramArrayOfByte)

Description

compress

Declaration

public static byte[] compress(byte[] paramArrayOfByte) throws Exception 

Method Source Code

//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import java.util.zip.GZIPOutputStream;

public class Main {
    public static String compress(String paramString) throws Exception {
        return new String(compress(paramString.getBytes("utf-8")), "utf-8");
    }/* ww  w  . jav a2  s  .c  o m*/

    public static byte[] compress(byte[] paramArrayOfByte) throws Exception {
        ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(
                paramArrayOfByte);
        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
        GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream(
                localByteArrayOutputStream);
        byte[] arrayOfByte = new byte[1024];
        for (;;) {
            int i = localByteArrayInputStream.read(arrayOfByte, 0, 1024);
            if (i == -1) {
                localGZIPOutputStream.flush();
                localGZIPOutputStream.finish();
                localGZIPOutputStream.close();
                return localByteArrayOutputStream.toByteArray();
            }
            localGZIPOutputStream.write(arrayOfByte, 0, i);
        }
    }
}

Related

  1. compress(byte[] data)
  2. compress(byte[] data)
  3. zipit(byte[] paramArrayOfByte)