Kenmegne
6 days ago 21b0e461d272751b3d6c2721395bf6375b41c5b3
move to new repo
15 files added
1506 ■■■■■ changed files
moteur-zip-megatim/.classpath 55 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/.project 23 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/.settings/org.eclipse.jdt.apt.core.prefs 2 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/.settings/org.eclipse.jdt.core.prefs 9 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/.settings/org.eclipse.m2e.core.prefs 4 ●●●● patch | view | raw | blame | history
moteur-zip-megatim/pom.xml 14 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/src/main/java/com/megatim/module/compression/Application.java 64 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/src/main/java/com/megatim/module/compression/ifaces/CompressionFace.java 161 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/src/main/java/com/megatim/module/compression/impl/JavaZipGZIPImpl.java 357 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/src/main/java/com/megatim/module/compression/impl/JavaZipGZLIBImpl.java 381 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/src/main/java/com/megatim/module/compression/impl/JavaZipZip4Impl.java 421 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/target/maven-archiver/pom.properties 5 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst 5 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst 5 ●●●●● patch | view | raw | blame | history
moteur-zip-megatim/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst patch | view | raw | blame | history
moteur-zip-megatim/.classpath
New file
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="target/generated-sources/annotations">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="ignore_optional_problems" value="true"/>
            <attribute name="m2e-apt" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="ignore_optional_problems" value="true"/>
            <attribute name="m2e-apt" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>
moteur-zip-megatim/.project
New file
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>moteur-zip-megatim</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
    </natures>
</projectDescription>
moteur-zip-megatim/.settings/org.eclipse.jdt.apt.core.prefs
New file
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
moteur-zip-megatim/.settings/org.eclipse.jdt.core.prefs
New file
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
moteur-zip-megatim/.settings/org.eclipse.m2e.core.prefs
New file
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
moteur-zip-megatim/pom.xml
New file
@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.megatim</groupId>
  <artifactId>module-compression</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>mgt-compression-module</name>
  <dependencies>
    <dependency>
        <groupId>net.lingala.zip4j</groupId>
        <artifactId>zip4j</artifactId>
        <version>2.9.1</version>
    </dependency>
  </dependencies>
</project>
moteur-zip-megatim/src/main/java/com/megatim/module/compression/Application.java
New file
@@ -0,0 +1,64 @@
package com.megatim.module.compression;
import java.io.File;
import com.megatim.module.compression.impl.JavaZipZip4Impl;
import com.megatim.module.compression.ifaces.CompressionFace;
public class Application {
    public static void main(String[] args) throws Exception {
//        testZip = new JavaZipGZLIB();
        JavaZipZip4Impl testZip = new JavaZipZip4Impl();
        File destination = new File("C:\\Users\\STEPHANIE\\Documents\\zip_test\\results");
       File testFile = new File("C:\\Users\\STEPHANIE\\Documents\\zip_test\\netbeans.exe");
        File zipTestFile = new File("C:\\Users\\STEPHANIE\\Documents\\zip_test\\netbeans.zip");
        File testRepertoire = new File("C:\\Users\\STEPHANIE\\Documents\\zip_test\\documentation");
        File zipTestRepertoire = new File("C:\\Users\\STEPHANIE\\Documents\\zip_test\\share_sources.zip");
         //---   zipper un fichier
//       testZip.zipFile(testFile, new File("D:\\sources\\mgt-archiage-module\\toto"));
        //--- Dezipper un fichier
//        testZip.unZipFile(zipTestFile, destination);
        //--- Zipper un repertoire
//        testZip.zipRepository(testRepertoire,destination);
        //--- Dezipper un repertoire
//        testZip.unZipRepository(zipTestRepertoire, testRepertoire);
        //--- Zipper un fichier avec mot de passe
        testZip.zipFile(testFile, destination,"megatim");
        //--- Dezipper un fichier avec mot de passe
//        testZip.unZipFile(zipTestFile, testRepertoire, "megatim");
        //--- Creer un repertoire  zipper avec mot de passe
        //testZip.zipRepository(testRepertoire, "megatim");
        //--- Dezipper un repertoire avec mot de passe
//        testZip.unZipRepository(zipTestRepertoire, testRepertoire, "megatim");
    //--- Ajouter un repertoire dans un fichier zipper avec mot de passe
//        testZip.addRepository(testRepertoire, zipTestRepertoire, "megatim");
        //--- Ajouter un fichier dans un fichier zipper
//        testZip.addFile(testFile, zipTestFile);
        //--- Ajouter un repertoire dans un fichier zipper
        //testZip.addRepository(testRepertoire, zipTestFile);
        //--- Ajouter un fichier dans un fichier zipper avec mot de passe
        //testZip.addFile(testFile, zipTestFile, "breakofdawn");
        //--- Ajouter un fichier dans un fichier zipper avec mot de passe
        //testZip.addFile(testFile, zipTestFile, "breakofdawn");
    }
}
moteur-zip-megatim/src/main/java/com/megatim/module/compression/ifaces/CompressionFace.java
New file
@@ -0,0 +1,161 @@
package com.megatim.module.compression.ifaces;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import net.lingala.zip4j.exception.ZipException;
//-----------------
// Interface methods
//-----------------
public interface CompressionFace {
    /**
     * Fonction permettant de compresser un fichier
     *
     * @param fichierAZipper
     * @author derteuffel
     * @return
     * @throws java.io.IOException
     *
     */
    public File zipFile(File fichierAZipper) throws IOException;
    public File zipFile(File fichierAZipper,File repertoireDestination) throws IOException;
    public File zipFile(File fichierAZipper,File repertoireDestination, String password) throws IOException;
    /**
     * Fonction permettant de compresser un repertoire
     *
     * @param repertoireAZipper
     * @author derteuffel
     * @return
     * @throws java.io.IOException
     *
     */
    public File zipRepository(File repertoireAZipper) throws IOException;
    public File zipRepository(File repertoireAZipper,File repertoireDestination) throws IOException;
    /**
     * Fonction permettant de decompresser un fichier
     *
     * @param fichierZipper
     * @author derteuffel
     * @param repertoireSorti
     * @throws java.io.IOException
     *
     */
    public void unZipFile(File fichierZipper, File repertoireSorti) throws IOException;
    /**
     * Fonction permettant de decompresser un repertoire
     *
     * @param repertoireZipper
     * @param repertoireSorti
     * @author derteuffel
     * @throws java.io.IOException
     *
     */
    public void unZipRepository(File repertoireZipper, File repertoireSorti) throws IOException;
    /**
     * Fonction permettant d'ajouter un fichier dans un zip
     *
     * @param fichier a ajouter
     * @param zipFile
     * @author derteuffel
     * @throws java.io.IOException
     *
     */
    public void addFile(File fichier, File zipFile) throws IOException, Exception;
    /**
     * Fonction permettant d'ajouter un repertoire dans un fichier zipper
     *
     * @param repository
     * @param zipFile
     * @author derteuffel
     * @throws java.io.FileNotFoundException
     *
     */
    public void addRepository(File repository, File zipFile) throws FileNotFoundException, Exception;
    /**
     * Fonction permettant de compresser un fichier avec un mot de passe
     *
     * @author derteuffel
     * @param fichierAZipper
     * @param password
     * @return
     * @throws net.lingala.zip4j.exception.ZipException
     * @throws java.lang.Exception
     *
     */
    public File zipFile(File fichierAZipper, String password) throws ZipException, Exception;
    /**
     * Fonction permettant de compresser un repertoire avec un mot de passe
     *
     * @author derteuffel
     * @param repertoireAZipper
     * @param password
     * @return
     * @throws java.lang.Exception
     *
     */
    public File zipRepository(File repertoireAZipper, String password) throws Exception;
    /**
     * Fonction permettant de decompresser un fichier avec un mot de passe
     *
     * @param fichierZipper
     * @author derteuffel
     * @param repertoireSorti
     * @param password
     * @throws java.lang.Exception
     *
     */
    public void unZipFile(File fichierZipper, File repertoireSorti, String password) throws Exception;
    /**
     * Fonction permettant de decompresser un repertoire avec un mot de passe
     *
     * @param repertoireZipper
     * @author derteuffel
     * @param repertoireSorti
     * @param password
     * @throws net.lingala.zip4j.exception.ZipException
     *
     */
    public void unZipRepository(File repertoireZipper, File repertoireSorti, String password) throws ZipException, Exception;
    /**
     * Fonction permettant d'ajouter un fichier dans un fichier zipper avec un
     * mot de passe
     *
     * @param fichier a ajouter
     * @param zipFile
     * @param password
     * @author derteuffel
     * @throws java.lang.Exception
     *
     */
    public void addFile(File fichier, File zipFile, String password) throws Exception;
    /**
     * Fonction permettant d'ajouter un rtepertoire dans un fichier zipper avec
     * un mot de passe
     *
     * @param repository a ajouter
     * @param zipFile zipper
     * @param password mot de passe
     * @author derteuffel
     * @throws java.lang.Exception
     *
     */
    public void addRepository(File repository, File zipFile, String password) throws Exception;
}
moteur-zip-megatim/src/main/java/com/megatim/module/compression/impl/JavaZipGZIPImpl.java
New file
@@ -0,0 +1,357 @@
package com.megatim.module.compression.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import net.lingala.zip4j.exception.ZipException;
import com.megatim.module.compression.ifaces.CompressionFace;
public class JavaZipGZIPImpl implements CompressionFace {
    public static int sChunk = 8192;
    public File zipFile(File fichierAZipper) throws IOException {
        // TODO Auto-generated method stub
        // create output stream
        String zipname = removeExtension(fichierAZipper.getPath()) + ".gz";
        GZIPOutputStream zipout;
        try {
            FileOutputStream out = new FileOutputStream(zipname);
            zipout = new GZIPOutputStream(out);
        } catch (IOException e) {
            System.out.println("Couldn't create " + zipname + ".");
            return null;
        }
        byte[] buffer = new byte[sChunk];
        // compress the file
        try {
            FileInputStream in = new FileInputStream(removeExtension(fichierAZipper.getPath()));
            int length;
            while ((length = in.read(buffer, 0, sChunk)) != -1) {
                zipout.write(buffer, 0, length);
            }
            in.close();
        } catch (IOException e) {
            System.out.println("Couldn't compress " + removeExtension(fichierAZipper.getPath()) + ".");
        }
        try {
            zipout.close();
        } catch (IOException e) {
        }
        return new File(removeExtension(fichierAZipper.getPath()) + ".gz");
    }
     public File zipFile(File fichierAZipper, File repertoireDestination) throws IOException {
         return null;
     }
    public File zipRepository(File repertoireAZipper) throws IOException {
        // TODO Auto-generated method stub
        // create output stream
        String zipname = repertoireAZipper.getPath() + ".gz";
        GZIPOutputStream zipout;
        try {
            FileOutputStream out = new FileOutputStream(zipname);
            zipout = new GZIPOutputStream(out);
        } catch (IOException e) {
            System.out.println("Couldn't create " + zipname + ".");
            return null;
        }
        byte[] buffer = new byte[sChunk];
        // compress the file
        try {
            FileInputStream in = new FileInputStream(repertoireAZipper.getPath());
            int length;
            while ((length = in.read(buffer, 0, sChunk)) != -1) {
                zipout.write(buffer, 0, length);
            }
            in.close();
        } catch (IOException e) {
            System.out.println("Couldn't compress " + repertoireAZipper.getPath() + ".");
        }
        try {
            zipout.close();
        } catch (IOException e) {
        }
        return new File(repertoireAZipper.getPath() + ".gz");
    }
     public File zipRepository(File repertoireAZipper, File repertoireDestination) throws IOException {
         return null;
     }
    public void unZipFile(File fichierZipper, File repertoireSorti) throws IOException {
        // TODO Auto-generated method stub
        // create input stream
        String zipname, source;
        if (fichierZipper.getPath().endsWith(".gz")) {
            zipname = fichierZipper.getPath();
            source = repertoireSorti.getPath();
        } else {
            zipname = fichierZipper.getPath() + ".gz";
            source = repertoireSorti.getPath();
        }
        GZIPInputStream zipin = null;
        try {
            FileInputStream in = new FileInputStream(zipname);
            zipin = new GZIPInputStream(in);
        } catch (IOException e) {
            System.out.println("Couldn't open " + zipname + ".");
            return;
        }
        byte[] buffer = new byte[sChunk];
        // decompress the file
        try {
            FileOutputStream out = new FileOutputStream(source);
            int length;
            while ((length = zipin.read(buffer, 0, sChunk)) != -1) {
                out.write(buffer, 0, length);
            }
            out.close();
        } catch (IOException e) {
            System.out.println("Couldn't decompress " + fichierZipper.getName() + ".");
        }
        try {
            zipin.close();
        } catch (IOException e) {
        }
    }
    public void unZipRepository(File repertoireZipper, File repertoireSorti) throws IOException {
        // TODO Auto-generated method stub
        // create input stream
        String zipname, source;
        if (repertoireZipper.getPath().endsWith(".gz")) {
            zipname = repertoireZipper.getPath();
            source = repertoireSorti.getPath();
        } else {
            zipname = repertoireZipper.getPath() + ".gz";
            source = repertoireSorti.getPath();
        }
        GZIPInputStream zipin = null;
        try {
            FileInputStream in = new FileInputStream(zipname);
            zipin = new GZIPInputStream(in);
        } catch (IOException e) {
            System.out.println("Couldn't open " + zipname + ".");
            return;
        }
        byte[] buffer = new byte[sChunk];
        // decompress the file
        try {
            FileOutputStream out = new FileOutputStream(source);
            int length;
            while ((length = zipin.read(buffer, 0, sChunk)) != -1) {
                out.write(buffer, 0, length);
            }
            out.close();
        } catch (IOException e) {
            System.out.println("Couldn't decompress " + repertoireZipper.getName() + ".");
        }
        try {
            zipin.close();
        } catch (IOException e) {
        }
    }
    public void addFile(File fichier, File zipFile) throws IOException, Exception {
        // TODO Auto-generated method stub
        // create output stream
        String zipname = zipFile.getPath();
        GZIPOutputStream zipout = null;
        try {
            FileOutputStream out = new FileOutputStream(zipname);
            zipout = new GZIPOutputStream(out);
        } catch (IOException e) {
            System.out.println("Couldn't create " + zipname + ".");
        }
        byte[] buffer = new byte[sChunk];
        // compress the file
        try {
            FileInputStream in = new FileInputStream(removeExtension(fichier.getPath()));
            int length;
            while ((length = in.read(buffer, 0, sChunk)) != -1) {
                zipout.write(buffer, 0, length);
            }
            in.close();
        } catch (IOException e) {
            System.out.println("Couldn't compress " + fichier + ".");
        }
        try {
            zipout.close();
        } catch (IOException e) {
        }
    }
    public void addRepository(File repository, File zipFile) throws FileNotFoundException, Exception {
        // TODO Auto-generated method stub
        // create output stream
        String zipname = zipFile.getPath();
        GZIPOutputStream zipout = null;
        try {
            FileOutputStream out = new FileOutputStream(zipname);
            zipout = new GZIPOutputStream(out);
        } catch (IOException e) {
            System.out.println("Couldn't create " + zipname + ".");
        }
        byte[] buffer = new byte[sChunk];
        // compress the file
        try {
            FileInputStream in = new FileInputStream(repository.getPath());
            int length;
            while ((length = in.read(buffer, 0, sChunk)) != -1) {
                zipout.write(buffer, 0, length);
            }
            in.close();
        } catch (IOException e) {
            System.out.println("Couldn't compress " + repository.getName() + ".");
        }
        try {
            zipout.close();
        } catch (IOException e) {
        }
    }
    public File zipFile(File fichierAZipper, String password) throws ZipException, Exception {
        // TODO Auto-generated method stub
        return null;
    }
    public File zipRepository(File repertoireAZipper, String password) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }
    public void unZipFile(File fichierZipper, File repertoireSorti, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    public void unZipRepository(File repertoireZipper, File repertoireSorti, String password)
            throws ZipException, Exception {
        // TODO Auto-generated method stub
    }
    public void addFile(File fichier, File zipFile, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    public void addRepository(File repository, File zipFile, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    // Remove extension before zip file
    public static String removeExtension(String s) {
        String separator = System.getProperty("file.separator");
        String filename;
        // Remove the path upto the filename.
        /*
             * int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex ==
             * -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1);
             * }
         */
        // Remove the extension.
        int extensionIndex = s.lastIndexOf(".");
        if (extensionIndex == -1) {
            return s;
        }
        return s.substring(0, extensionIndex);
    }
     public File zipFile(File fichierAZipper,File repertoireDestination, String password) throws IOException {
         return null;
     }
}
moteur-zip-megatim/src/main/java/com/megatim/module/compression/impl/JavaZipGZLIBImpl.java
New file
@@ -0,0 +1,381 @@
package com.megatim.module.compression.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import com.megatim.module.compression.ifaces.CompressionFace;
/**
 * Classe implementant l'algorithme GZLIB
 *
 * @author derteuffel
 *
 */
public class JavaZipGZLIBImpl implements CompressionFace {
    // Zip file
    public File zipFile(File fichierAZipper) throws IOException {
        // TODO Auto-generated method stub
        String sourceFile = fichierAZipper.getAbsolutePath();
        System.out.println(sourceFile);
        // initialisation du fichier zipper avec retrai de l'extencion
        FileOutputStream fos = new FileOutputStream(removeExtension(sourceFile) + ".zip");
        ZipOutputStream zipOut = new ZipOutputStream(fos);
        File fileToZip = new File(sourceFile);
        FileInputStream fis = new FileInputStream(fileToZip);
        ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
        zipOut.putNextEntry(zipEntry);
        byte[] bytes = new byte[1024];
        int length;
        while ((length = fis.read(bytes)) >= 0) {
            zipOut.write(bytes, 0, length);
        }
        zipOut.close();
        fis.close();
        fos.close();
        System.out.println("Zippage terminer");
        return fileToZip;
    }
     public File zipFile(File fichierAZipper, File repertoireDestination) throws IOException {
         return null;
     }
    // Zip directory
    public File zipRepository(File repertoireAZipper) throws IOException {
        // TODO Auto-generated method stub
        // Charger le chemin du repertoir a zipper
        String sourceFile = repertoireAZipper.getAbsolutePath();
        // initialisation du nom du repertoir zipper
        FileOutputStream fos = new FileOutputStream(sourceFile + ".zip");
        ZipOutputStream zipOut = new ZipOutputStream(fos);
        File fileToZip = new File(sourceFile);
        zipFile(fileToZip, fileToZip.getName(), zipOut);
        zipOut.close();
        fos.close();
        return fileToZip;
    }
     public File zipRepository(File repertoireAZipper, File repertoireDestination) throws IOException {
         return null;
     }
    // Dezipper un fichier zipper
    public void unZipFile(File fichierZipper, File repertoireSorti) throws IOException {
        // TODO Auto-generated method stub
        //Initialisation du chemin du fichier zipper a dezipper
        String fileZip = fichierZipper.getAbsolutePath();
        // Initialisation du chemin destination  du fichier zipper a dezipper
        File destDir = new File(repertoireSorti.getAbsolutePath());
        if (destDir.mkdirs()) {
            System.out.println("Repertoi de sorti creer");
        } else {
            System.out.println("Repertoir de sorti existant");
        }
        byte[] buffer = new byte[1024];
        ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
        ZipEntry zipEntry = zis.getNextEntry();
        while (zipEntry != null) {
            File newFile = newFile(destDir, zipEntry);
            // Test si le fichier contenu est un repertoir ou un fichier
            if (zipEntry.isDirectory()) {
                if (!newFile.isDirectory() && !newFile.mkdirs()) {
                    throw new IOException("Failed to create directory " + newFile);
                }
            } else {
                // fix for Windows-created archives
                File parent = newFile.getParentFile();
                if (!parent.isDirectory() && !parent.mkdirs()) {
                    throw new IOException("Failed to create directory " + parent);
                }
                // write file content
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
            }
            zipEntry = zis.getNextEntry();
        }
        zis.closeEntry();
        zis.close();
    }
    // Dezipper un repertoir
    public void unZipRepository(File repertoireZipper, File repertoireSorti) throws IOException {
        // TODO Auto-generated method stub
        //Initialisation du chemin du fichier zipper a dezipper
        String fileZip = repertoireZipper.getAbsolutePath();
        // Initialisation du chemin destination  du fichier zipper a dezipper
        File destDir = new File(repertoireSorti.getAbsolutePath());
        if (destDir.mkdirs()) {
            System.out.println("Repertoi de sorti creer");
        } else {
            System.out.println("Repertoir de sorti existant");
        }
        byte[] buffer = new byte[1024];
        ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
        ZipEntry zipEntry = zis.getNextEntry();
        while (zipEntry != null) {
            File newFile = newFile(destDir, zipEntry);
            // Test si le fichier contenu est un repertoir ou un fichier
            if (zipEntry.isDirectory()) {
                if (!newFile.isDirectory() && !newFile.mkdirs()) {
                    throw new IOException("Failed to create directory " + newFile);
                }
            } else {
                // fix for Windows-created archives
                File parent = newFile.getParentFile();
                if (!parent.isDirectory() && !parent.mkdirs()) {
                    throw new IOException("Failed to create directory " + parent);
                }
                // write file content
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
            }
            zipEntry = zis.getNextEntry();
        }
        zis.closeEntry();
        zis.close();
    }
    public void addFile(File fichier, File zipFile) throws Exception {
        // TODO Auto-generated method stub
    }
    // Add repository to existed zip file
    public void addRepository(File repository, File zipFile) throws Exception {
        // TODO Auto-generated method stub
    }
    // Zip file with password
    public File zipFile(File fichierAZipper, String password) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }
    // Zip directory with passwor
    public File zipRepository(File repertoireAZipper, String password) throws Exception {
        // TODO Auto-generated method stub
        return null;
    }
    // dezippage d'un fichier zipper
    public void unZipFile(File fichierZipper, File repertoireSorti, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    // Dezipper un repertoire
    public void unZipRepository(File repertoireZipper, File repertoireSorti, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    public void addFile(File fichier, File zipFile, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    public void addRepository(File repository, File zipFile, String password) throws Exception {
        // TODO Auto-generated method stub
    }
    // Remove extension before zip file
    public static String removeExtension(String s) {
        String separator = System.getProperty("file.separator");
        String filename;
        // Remove the path upto the filename.
        /*
         * int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex ==
         * -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1);
         * }
         */
        // Remove the extension.
        int extensionIndex = s.lastIndexOf(".");
        if (extensionIndex == -1) {
            return s;
        }
        return s.substring(0, extensionIndex);
    }
    // create directory and check if there are many contained files
    private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException {
        if (fileToZip.isHidden()) {
            return;
        }
        if (fileToZip.isDirectory()) {
            if (fileName.endsWith("/")) {
                zipOut.putNextEntry(new ZipEntry(fileName));
                zipOut.closeEntry();
            } else {
                zipOut.putNextEntry(new ZipEntry(fileName + "/"));
                zipOut.closeEntry();
            }
            File[] children = fileToZip.listFiles();
            for (File childFile : children) {
                zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);
            }
            return;
        }
        FileInputStream fis = new FileInputStream(fileToZip);
        ZipEntry zipEntry = new ZipEntry(fileName);
        zipOut.putNextEntry(zipEntry);
        byte[] bytes = new byte[1024];
        int length;
        while ((length = fis.read(bytes)) >= 0) {
            zipOut.write(bytes, 0, length);
        }
        fis.close();
    }
    // Create new file after unzip
    public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
        File destFile = new File(destinationDir, zipEntry.getName());
        String destDirPath = destinationDir.getCanonicalPath();
        String destFilePath = destFile.getCanonicalPath();
        if (!destFilePath.startsWith(destDirPath + File.separator)) {
            throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
        }
        return destFile;
    }
     public File zipFile(File fichierAZipper,File repertoireDestination, String password) throws IOException {
         return null;
     }
}
moteur-zip-megatim/src/main/java/com/megatim/module/compression/impl/JavaZipZip4Impl.java
New file
@@ -0,0 +1,421 @@
package com.megatim.module.compression.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.CompressionLevel;
import net.lingala.zip4j.model.enums.EncryptionMethod;
import com.megatim.module.compression.ifaces.CompressionFace;
import java.util.Arrays;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.enums.CompressionMethod;
/**
 * Classe implementant l'algorithme Zip4J
 *
 * @author derteuffel
 *
 */
public class JavaZipZip4Impl implements CompressionFace {
    public void zipFile(File sourceFile, File destinationFolder, int splitLength) throws ZipException {
        ZipParameters zipParameters = new ZipParameters();
        zipParameters.setCompressionMethod(CompressionMethod.DEFLATE);
        zipParameters.setCompressionLevel(CompressionLevel.NORMAL);
        ZipFile zipFile = new ZipFile(new File(destinationFolder.getAbsolutePath(), removeExtension(sourceFile.getName()) + ".zip"));
        // Create the split zip file from a single file
        zipFile.createSplitZipFile(Arrays.asList(sourceFile), zipParameters, true, splitLength * 1024 * 1024);
    }
    public void mergeSplitFiles(File mainZip, File destinationDir, String outputName) throws ZipException {
        // Create a ZipFile instance for the first part
        ZipFile zipFile = new ZipFile(mainZip);
        File mergedZipFile = new File(destinationDir, outputName);
        // Merge the split files into a single ZIP file
        zipFile.mergeSplitFiles(mergedZipFile);
    }
    public File zipFile(File fichierAZipper) throws IOException {
        // TODO Auto-generated method stub
        ZipFile zipFile = new ZipFile(removeExtension(fichierAZipper.getPath()) + ".zip");
        zipFile.addFile(new File(fichierAZipper.getPath()));
        // return new File(removeExtension(fichierAZipper.getPath()) + ".zip");
        return zipFile.getFile();
    }
    public File zipFile(File fichierAZipper, File destination) throws IOException {
        // TODO Auto-generated method stub
        ZipFile zipFile = new ZipFile(new File(destination.getPath(), removeExtension(fichierAZipper.getName()) + ".zip"));
        zipFile.addFile(fichierAZipper);
        return zipFile.getFile();
    }
    public File zipRepository(File repertoireAZipper, File destination) throws IOException {
        // TODO Auto-generated method stub
        ZipFile zipFile = new ZipFile(new File(destination.getPath(), removeExtension(repertoireAZipper.getName()) + ".zip"));
        zipFile.addFolder(repertoireAZipper);
        return zipFile.getFile();
    }
    public File zipFile(File fichierAZipper, File repertoireDestination, String password) throws IOException {
        String sourceFile = fichierAZipper.getAbsolutePath();
        ZipParameters zipParameters = new ZipParameters();
        zipParameters.setEncryptFiles(true);
        zipParameters.setCompressionLevel(CompressionLevel.HIGHER);
        zipParameters.setEncryptionMethod(EncryptionMethod.AES);
        File fileToAdd = new File(sourceFile);
        if (!fileToAdd.exists()) {
            fileToAdd.createNewFile();
        }
        ZipFile zipFile = new ZipFile(new File(repertoireDestination.getPath(), removeExtension(fichierAZipper.getName()) + ".zip"), password.toCharArray());
        zipFile.addFile(fichierAZipper, zipParameters);
        zipFile.close();
        return zipFile.getFile();
    }
    // Zip directory
    public File zipRepository(File repertoireAZipper) throws IOException {
        // TODO Auto-generated method stub
        new ZipFile(removeExtension(repertoireAZipper.getPath()) + ".zip").addFolder(new File(repertoireAZipper.getPath()));
        return new File(removeExtension(repertoireAZipper.getPath()) + ".zip");
    }
    // Dezipper un fichier zipper
    public void unZipFile(File fichierZipper, File repertoireSorti) throws IOException {
        // TODO Auto-generated method stub
        new ZipFile(removeExtension(fichierZipper.getPath()) + ".zip").extractAll(repertoireSorti.getPath());
    }
    // Dezipper un repertoir
    public void unZipRepository(File repertoireZipper, File repertoireSorti) throws IOException {
        // TODO Auto-generated method stub
        new ZipFile(removeExtension(repertoireZipper.getPath()) + ".zip").extractAll(repertoireSorti.getPath());
    }
    public void addFile(File fichier, File zipFile) throws Exception {
        // TODO Auto-generated method stub
        if (zipFile.createNewFile()) {
            System.out.println("Zip file created");
        } else {
            System.out.println("Zip file already exist");
        }
        new ZipFile(zipFile.getPath()).addFile(new File(fichier.getPath()));
    }
    // Add repository to existed zip file
    public void addRepository(File repository, File zipFile) throws Exception {
        // TODO Auto-generated method stub
        if (zipFile.createNewFile()) {
            System.out.println("Zip file created");
        } else {
            System.out.println("Zip file already exist");
        }
        new ZipFile(zipFile.getPath()).addFolder(new File(repository.getPath()));
    }
    // Zip file with password
    public File zipFile(File fichierAZipper, String password) throws Exception {
        // TODO Auto-generated method stub
        String sourceFile = fichierAZipper.getAbsolutePath();
        ZipParameters zipParameters = new ZipParameters();
        zipParameters.setEncryptFiles(true);
        zipParameters.setCompressionLevel(CompressionLevel.HIGHER);
        zipParameters.setEncryptionMethod(EncryptionMethod.AES);
        File fileToAdd = new File(sourceFile);
        if (!fileToAdd.exists()) {
            fileToAdd.createNewFile();
        }
        ZipFile zipFile = new ZipFile(removeExtension(fileToAdd.getPath()) + ".zip", password.toCharArray());
        zipFile.addFile(fileToAdd, zipParameters);
        zipFile.close();
        return new File(removeExtension(fileToAdd.getPath()) + ".zip");
    }
    // Zip directory with passwor
    public File zipRepository(File repertoireAZipper, String password) throws Exception {
        // TODO Auto-generated method stub
        String sourceFile = repertoireAZipper.getAbsolutePath();
        ZipParameters zipParameters = new ZipParameters();
        zipParameters.setEncryptFiles(true);
        zipParameters.setCompressionLevel(CompressionLevel.HIGHER);
        zipParameters.setEncryptionMethod(EncryptionMethod.AES);
        File fileToAdd = new File(sourceFile);
        if (!fileToAdd.exists()) {
            fileToAdd.mkdirs();
        }
        ZipFile zipFile = new ZipFile(removeExtension(fileToAdd.getPath()) + ".zip", password.toCharArray());
        zipFile.addFolder(fileToAdd, zipParameters);
        zipFile.close();
        return new File(removeExtension(fileToAdd.getPath()) + ".zip");
    }
    // dezippage d'un fichier zipper
    public void unZipFile(File fichierZipper, File repertoireSorti, String password) throws Exception {
        // TODO Auto-generated method stub
        String sourceFile = repertoireSorti.getAbsolutePath();
        File outFile = new File(sourceFile);
        // Check if directory exist
        if (!outFile.exists()) {
            outFile.mkdirs();
        }
        // Initialize zip file reader to prepare extraction
        ZipFile zipFile = new ZipFile(fichierZipper.getPath(), password.toCharArray());
        zipFile.extractAll(outFile.getPath());
        // Close the reader
        zipFile.close();
    }
    // Dezipper un repertoire
    public void unZipRepository(File repertoireZipper, File repertoireSorti, String password) throws Exception {
        // TODO Auto-generated method stub
        String sourceFile = repertoireSorti.getAbsolutePath();
        File outFile = new File(sourceFile);
        // Check if directory exist
        if (!outFile.exists()) {
            outFile.mkdirs();
        }
        // Initialize zip file reader to prepare extraction
        ZipFile zipFile = new ZipFile(repertoireZipper.getPath(), password.toCharArray());
        zipFile.extractAll(outFile.getPath());
        // Close the reader
        zipFile.close();
    }
    public void addFile(File fichier, File zipFile, String password) throws Exception {
        // TODO Auto-generated method stub
        // Test d'existance du repertoire de destination
        if (zipFile.createNewFile()) {
            System.out.println("Zip file created");
        } else {
            System.out.println("Zip file already exist");
        }
        ZipParameters zipParameters = new ZipParameters();
        zipParameters.setEncryptFiles(true);
        zipParameters.setCompressionLevel(CompressionLevel.HIGHER);
        zipParameters.setEncryptionMethod(EncryptionMethod.AES);
        //Ajouter le fichier dans le fichier zipper et association du mot de passe
        new ZipFile(zipFile.getPath(), password.toCharArray()).addFile(new File(fichier.getPath()), zipParameters);
    }
    public void addRepository(File repository, File zipFile, String password) throws Exception {
        // TODO Auto-generated method stub
        //Test d'existance du repertoire de destination
        if (zipFile.createNewFile()) {
            System.out.println("Zip file created");
        } else {
            System.out.println("Zip file already exist");
        }
        ZipParameters zipParameters = new ZipParameters();
        zipParameters.setEncryptFiles(true);
        zipParameters.setCompressionLevel(CompressionLevel.HIGHER);
        zipParameters.setEncryptionMethod(EncryptionMethod.AES);
        //Ajouter le repertoire dans le fichier zipper et association du mot de passe
        new ZipFile(zipFile.getPath(), password.toCharArray()).addFolder(new File(repository.getPath()), zipParameters);
    }
    // Remove extension before zip file
    public static String removeExtension(String s) {
        String separator = System.getProperty("file.separator");
        String filename;
        // Remove the path upto the filename.
        /*
         * int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex ==
         * -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1);
         * }
         */
        // Remove the extension.
        int extensionIndex = s.lastIndexOf(".");
        if (extensionIndex == -1) {
            return s;
        }
        return s.substring(0, extensionIndex);
    }
    // create directory and check if there are many contained files
    private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException {
        if (fileToZip.isHidden()) {
            return;
        }
        if (fileToZip.isDirectory()) {
            if (fileName.endsWith("/")) {
                zipOut.putNextEntry(new ZipEntry(fileName));
                zipOut.closeEntry();
            } else {
                zipOut.putNextEntry(new ZipEntry(fileName + "/"));
                zipOut.closeEntry();
            }
            File[] children = fileToZip.listFiles();
            for (File childFile : children) {
                zipFile(childFile, fileName + "/" + childFile.getName(), zipOut);
            }
            return;
        }
        FileInputStream fis = new FileInputStream(fileToZip);
        ZipEntry zipEntry = new ZipEntry(fileName);
        zipOut.putNextEntry(zipEntry);
        byte[] bytes = new byte[1024];
        int length;
        while ((length = fis.read(bytes)) >= 0) {
            zipOut.write(bytes, 0, length);
        }
        fis.close();
    }
    // Create new file after unzip
    public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
        File destFile = new File(destinationDir, zipEntry.getName());
        String destDirPath = destinationDir.getCanonicalPath();
        String destFilePath = destFile.getCanonicalPath();
        if (!destFilePath.startsWith(destDirPath + File.separator)) {
            throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
        }
        return destFile;
    }
}
moteur-zip-megatim/target/maven-archiver/pom.properties
New file
@@ -0,0 +1,5 @@
#Generated by Maven
#Tue Dec 09 16:48:37 WAT 2025
version=0.0.1-SNAPSHOT
groupId=com.megatim
artifactId=module-compression
moteur-zip-megatim/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
New file
@@ -0,0 +1,5 @@
com\megatim\module\compression\impl\JavaZipGZLIBImpl.class
com\megatim\module\compression\impl\JavaZipZip4Impl.class
com\megatim\module\compression\impl\JavaZipGZIPImpl.class
com\megatim\module\compression\ifaces\CompressionFace.class
com\megatim\module\compression\Application.class
moteur-zip-megatim/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
New file
@@ -0,0 +1,5 @@
C:\Users\ASUS\Documents\NetBeansProjects\share_sources\moteur-zip-megatim\src\main\java\com\megatim\module\compression\Application.java
C:\Users\ASUS\Documents\NetBeansProjects\share_sources\moteur-zip-megatim\src\main\java\com\megatim\module\compression\ifaces\CompressionFace.java
C:\Users\ASUS\Documents\NetBeansProjects\share_sources\moteur-zip-megatim\src\main\java\com\megatim\module\compression\impl\JavaZipGZLIBImpl.java
C:\Users\ASUS\Documents\NetBeansProjects\share_sources\moteur-zip-megatim\src\main\java\com\megatim\module\compression\impl\JavaZipGZIPImpl.java
C:\Users\ASUS\Documents\NetBeansProjects\share_sources\moteur-zip-megatim\src\main\java\com\megatim\module\compression\impl\JavaZipZip4Impl.java
moteur-zip-megatim/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst