package ru.matevosyan;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * Created for zipping file from archive.
 * Created on 19.02.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class ZipWithStructure {

    private String FOLDER_PATH_NAME;

    public ZipWithStructure(String folder_path_name) {
        FOLDER_PATH_NAME = folder_path_name;
    }
    private List<String> listOfFile = new ArrayList<>();

    public void zipping(String outZip) throws IOException {

        try (FileOutputStream fos = new FileOutputStream(outZip); ZipOutputStream zos = new ZipOutputStream(fos)) {

            int length;
            byte[] bytes = new byte[1024];

            for (String fileName : this.listOfFile) {
                ZipEntry zipEntry = new ZipEntry(fileName);
                zos.putNextEntry(zipEntry);

                FileInputStream fis = new FileInputStream(FOLDER_PATH_NAME + File.separator + fileName);

                while ((length = fis.read(bytes)) > 0) {
                    zos.write(bytes, 0, length);
                }
            }

            zos.closeEntry();
        } catch (FileNotFoundException fnf) {
            fnf.getMessage();
        }
    }

    public void genListOfFiles(File fileObject, String ... extension) {
        if (fileObject.exists()) {
            if (fileObject.isFile()) {
                for (int i = 0; i < extension.length; i++) {
                    String anExtension = extension[i];
                    if (fileObject.toString().endsWith("." + anExtension)) {
                        this.listOfFile.add(getEntryNameOfFile(fileObject.getAbsoluteFile().toString()));
                    }
                }
            }

            if (fileObject.isDirectory()) {
                String[] fileList = fileObject.list();

                if (fileList != null) {
                    for (String file : fileList) {
                        genListOfFiles(new File(fileObject, file), extension);
                    }
                }
            }
        }
    }

    private String getEntryNameOfFile(String name) {
        return name.substring(FOLDER_PATH_NAME.length() + 1, name.length());
    }
}

@@ -117,16 +117,53 @@
 pEntry;%0A
+import java.util.zip.ZipInputStream;%0A
 import j
@@ -546,24 +546,1408 @@
 yList%3C%3E();%0A%0A
+    public void unzipping(String file, String folder) throws IOException%7B%0A%0A        createdDir(folder);%0A%0A        try (FileInputStream fileInputStream = new FileInputStream(file);%0A            ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) %7B%0A%0A            ZipEntry entry = zipInputStream.getNextEntry();%0A%0A            byte%5B%5D byteArray = new byte%5B1024%5D;%0A            int length;%0A            while(entry != null) %7B%0A                String fileName = entry.getName();%0A%0A%0A                File newFile = new File(folder + File.separator + fileName);%0A                //%22D:%5C%5CTracker-1.0-shaded.jar%22 %5C%5CFile.java%0A%0A                new File(newFile.getParent()).mkdirs();%0A%0A%0A                while ((length = fileInputStream.read(byteArray)) %3E 0) %7B%0A%0A                    try (FileOutputStream fos = new FileOutputStream(newFile)) %7B%0A%0A                        fos.write(byteArray, 0, length);%0A                    %7D catch (FileNotFoundException fnf) %7B%0A                            fnf.getMessage();%0A                    %7D%0A%0A                %7D%0A%0A                entry = zipInputStream.getNextEntry();%0A            %7D%0A%0A            zipInputStream.closeEntry();%0A        %7D catch (IOException ioe) %7B%0A            ioe.getMessage();%0A        %7D%0A    %7D%0A%0A    private void createdDir(String folder) %7B%0A        File dir = new File(folder);%0A%0A        if (!dir.exists()) %7B%0A            dir.mkdir();%0A        %7D%0A    %7D%0A%0A
     public v

add unzipping