Here you can find the source of deflate(byte[] input)
Parameter | Description |
---|---|
input | byte[] |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] deflate(byte[] input) throws IOException
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.DeflaterOutputStream; public class Main { /**/*from www. jav a 2s .c om*/ * Field BUF_LEN */ private static int BUF_LEN = 1024; /** * Method deflate * @param input byte[] * @return byte[] * @throws IOException */ public static byte[] deflate(byte[] input) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(input); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(bos); byte[] buffer = new byte[BUF_LEN]; int bytesRead = bis.read(buffer); while (bytesRead > 0) { dos.write(buffer, 0, bytesRead); bytesRead = bis.read(buffer); } dos.close(); return bos.toByteArray(); } }