Java Uncompress Byte Array unzip(byte[] content)

Here you can find the source of unzip(byte[] content)

Description

unzip

License

Apache License

Declaration

public static byte[] unzip(byte[] content) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2011 Clockwork/*from  w  ww. j a  v a 2 s  .c  om*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

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

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static byte[] unzip(byte[] content) throws IOException {
        int BUFFER_SIZE = 2048;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(content));
        ZipEntry entry = zin.getNextEntry();
        if (entry != null) {
            int count;
            byte buffer[] = new byte[BUFFER_SIZE];
            BufferedOutputStream bout = new BufferedOutputStream(out, BUFFER_SIZE);
            while ((count = zin.read(buffer, 0, BUFFER_SIZE)) != -1)
                bout.write(buffer, 0, count);
            bout.flush();
            bout.close();
            zin.close();
        }
        return out.toByteArray();
    }
}

Related

  1. unzip(byte[] bytes)
  2. unzip(byte[] bytes)
  3. unzip(byte[] bytes, String encoding)
  4. unzip(byte[] compressedByte)
  5. unzip(byte[] compressedData)
  6. unzip(byte[] content)
  7. unZip(byte[] contents)
  8. unzip(byte[] data)
  9. unZip(byte[] data)