Java Zip Byte Array zip(byte[] input)

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

Description

zip

License

Apache License

Declaration

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

Method Source Code

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.GZIPOutputStream;

public class Main {
    public static byte[] zip(byte[] input) {
        if (input == null || input.length == 0) {
            return input;
        }//from   ww w  .j  a  va 2s  .c o m
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            GZIPOutputStream gzip = new GZIPOutputStream(out);
            gzip.write(input);
            gzip.close();
            return out.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. zip(byte[] bytes)
  2. zip(byte[] data)
  3. zip(byte[] datas)
  4. zip(byte[] in)
  5. zip(byte[] input)
  6. zip(byte[] source)
  7. zip(byte[] uncompressedBytes)
  8. zipByte(byte[] data)
  9. zipBytes(byte[] input)