Here you can find the source of unzip(byte[] content)
Parameter | Description |
---|---|
content | byte[] |
Parameter | Description |
---|---|
IOException | an exception |
public static String unzip(byte[] content) throws IOException
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.InflaterInputStream; public class Main { /**/* w w w . jav a2s . c om*/ * Field BUF_LEN */ private static int BUF_LEN = 1024; /** * Method unzip * @param content byte[] * @return String * @throws IOException */ public static String unzip(byte[] content) throws IOException { return new String(inflate(content)); } /** * Method inflate * @param input byte[] * @return byte[] * @throws IOException */ public static byte[] inflate(byte[] input) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(input); InflaterInputStream iis = new InflaterInputStream(bis); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[BUF_LEN]; int bytesRead = iis.read(buffer); while (bytesRead > 0) { bos.write(buffer, 0, bytesRead); bytesRead = iis.read(buffer); } bos.flush(); return bos.toByteArray(); } }