Android Zip Unzip Directory compress(String paramString)

Here you can find the source of compress(String paramString)

Description

compress

Declaration

public static String compress(String paramString) 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");
    }//from   w  w  w.j a  va2s.  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. zipFileAtPath(final String sourcePath, final String toLocation)
  2. zipDirectory(File directory, File zip)
  3. zipDirectory(File directory, File zip)
  4. zipDirectory(File folder, String parentFolder, ZipOutputStream zos)
  5. compress(String filePath, int width, int height)
  6. compress(String path)
  7. compress(String path)
  8. compress(String path, boolean delete)
  9. compress(String path, boolean delete)