Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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 {
    /**
     * 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();
    }
}