Java Decompress Byte Array decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)

Here you can find the source of decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)

Description

Decompresses a given byte array that is a compressed folder.

License

Open Source License

Parameter

Parameter Description
folderAsCompressedArray to decompress
unzippedLocation where the decompressed folder should be

Exception

Parameter Description
IOException e
FileNotFoundException e

Declaration

public static void decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
        throws IOException, FileNotFoundException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayInputStream;
import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

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

public class Main {
    /**/*from   w ww .  ja  v a2  s.c  o m*/
     * Decompresses a given byte array that is a compressed folder.
     * 
     * @param folderAsCompressedArray to decompress
     * @param unzippedLocation where the decompressed folder should be
     * @throws IOException e
     * @throws FileNotFoundException e
     */
    public static void decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
            throws IOException, FileNotFoundException {
        ZipInputStream zipFile = new ZipInputStream(new ByteArrayInputStream(folderAsCompressedArray));
        ZipEntry ze = null;
        final int minusOne = -1;
        while ((ze = zipFile.getNextEntry()) != null) {
            FileOutputStream fout = new FileOutputStream(
                    new File(unzippedLocation, ze.getName()).getAbsolutePath());
            for (int c = zipFile.read(); c != minusOne; c = zipFile.read()) {
                fout.write(c);
            }
            zipFile.closeEntry();
            fout.close();
        }
        zipFile.close();
    }
}

Related

  1. decompressByteArray(byte[] compressedData)
  2. decompressBytes(byte bytess[][])
  3. decompressBytes(byte[] input)
  4. decompressByZLIB(byte[] compressedBytes)
  5. decompressData(byte[] compressedInput)
  6. decompressGzip(byte[] compressed)
  7. decompressGZIP(byte[] data)
  8. decompressGzipByteArray(byte[] compressedByteArray)
  9. decompressObject(byte[] bytes)