Java Zip Byte Array zip(byte[] data)

Here you can find the source of zip(byte[] data)

Description

zip

License

Apache License

Declaration

public static byte[] zip(byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {

    public static byte[] zip(byte[] data) {
        byte[] b = null;
        try {/*ww  w .ja  va  2 s.  c  om*/
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ZipOutputStream zip = new ZipOutputStream(bos);
            ZipEntry entry = new ZipEntry("zip");
            entry.setSize(data.length);
            zip.putNextEntry(entry);
            zip.write(data);
            zip.closeEntry();
            zip.close();
            b = bos.toByteArray();
            bos.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return b;
    }
}

Related

  1. doZip(byte[] data)
  2. zip(byte[] bytes)
  3. zip(byte[] datas)
  4. zip(byte[] in)
  5. zip(byte[] input)
  6. zip(byte[] input)