Java Deflate Byte Array deflate(byte[] array)

Here you can find the source of deflate(byte[] array)

Description

deflate

License

Apache License

Declaration

public static void deflate(byte[] array) throws IOException 

Method Source Code

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

import java.util.zip.InflaterInputStream;

public class Main {
    public static void deflate(byte[] array) throws IOException {
        InputStream in = new InflaterInputStream(new ByteArrayInputStream(array));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        shovelInToOut(in, bos);/*w ww . j a v  a  2 s  . c o  m*/
        in.close();
        System.out.println(bos.toString("UTF-8"));

    }

    private static void shovelInToOut(InputStream in, OutputStream out) throws IOException

    {
        byte[] buffer = new byte[1000];
        int len;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
    }
}

Related

  1. deflate(byte[] buf)
  2. deflate(byte[] bytes)
  3. deflate(byte[] data)
  4. deflate(byte[] data)