Search in sources :

Example 1 with ZipFile

use of net.lingala.zip4j.ZipFile in project yyl_example by Relucent.

the class Zip4JExample method upzip.

/**
 * 解压文件
 */
private static void upzip(File file) throws ZipException, IOException {
    ZipFile zipFile = new ZipFile(file);
    if (zipFile.isEncrypted()) {
        zipFile.setPassword(PASSWORD);
    }
    for (Object fh : zipFile.getFileHeaders()) {
        FileHeader header = (FileHeader) fh;
        System.out.println(header.getFileName());
    // header.isDirectory()
    // ZipInputStream zipInput = zipFile.getInputStream(header);
    }
    // zip文件名去掉后缀,作为解压的目录名
    String path = file.getAbsolutePath();
    String destPath = path.substring(0, path.lastIndexOf('.'));
    System.out.println("destPath: " + destPath);
    zipFile.extractAll(destPath);
}
Also used : ZipFile(net.lingala.zip4j.ZipFile) FileHeader(net.lingala.zip4j.model.FileHeader)

Example 2 with ZipFile

use of net.lingala.zip4j.ZipFile in project project-build-plugin by axonivy.

the class InstallEngineMojo method unpackEngine.

private void unpackEngine(File downloadZip) throws MojoExecutionException {
    try {
        String targetLocation = getRawEngineDirectory().getAbsolutePath();
        getLog().info("Unpacking engine " + downloadZip.getAbsolutePath() + " to " + targetLocation);
        ZipFile engineZip = new ZipFile(downloadZip);
        engineZip.extractAll(targetLocation);
    } catch (ZipException ex) {
        throw new MojoExecutionException("Failed to unpack downloaded engine '" + downloadZip + "'.", ex);
    }
}
Also used : ZipFile(net.lingala.zip4j.ZipFile) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ZipException(net.lingala.zip4j.exception.ZipException)

Example 3 with ZipFile

use of net.lingala.zip4j.ZipFile in project project-build-plugin by axonivy.

the class TestInstallEngineMojo method createFakeEngineZip.

private static File createFakeEngineZip(String ivyVersion) throws IOException, ZipException {
    File zipDir = createFakeEngineDir(ivyVersion);
    File zipFile = new File(zipDir, "fake.zip");
    ZipFile zip = new ZipFile(zipFile);
    zip.createSplitZipFileFromFolder(new File(zipDir, OsgiDir.INSTALL_AREA), new ZipParameters(), false, 0);
    return zipFile;
}
Also used : ZipFile(net.lingala.zip4j.ZipFile) File(java.io.File) ZipFile(net.lingala.zip4j.ZipFile) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Example 4 with ZipFile

use of net.lingala.zip4j.ZipFile in project J2ME-Loader by nikita36078.

the class ZipUtils method unzipEntry.

public static void unzipEntry(File srcZip, String name, File dst) throws IOException {
    ZipFile zip = new ZipFile(srcZip);
    FileHeader entry = zip.getFileHeader(name);
    if (entry == null) {
        throw new IOException("Entry '" + name + "' not found in zip: " + srcZip);
    }
    try (BufferedInputStream bis = new BufferedInputStream(zip.getInputStream(entry));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dst), BUFFER_SIZE)) {
        byte[] data = new byte[BUFFER_SIZE];
        int read;
        while ((read = bis.read(data)) != -1) {
            bos.write(data, 0, read);
        }
    }
}
Also used : ZipFile(net.lingala.zip4j.ZipFile) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileHeader(net.lingala.zip4j.model.FileHeader) BufferedOutputStream(java.io.BufferedOutputStream)

Example 5 with ZipFile

use of net.lingala.zip4j.ZipFile in project J2ME-Loader by nikita36078.

the class AppClassLoader method getResourceBytes.

private static byte[] getResourceBytes(String name) {
    if (zipFile == null) {
        final File file = new File(oldResDir, name);
        try {
            FileInputStream fis = new FileInputStream(file);
            byte[] data = IOUtils.toByteArray(fis);
            fis.close();
            return data;
        } catch (Exception e) {
            Log.w(TAG, "getResourceBytes: from file=" + file, e);
            return null;
        }
    }
    DataInputStream dis = null;
    try {
        FileHeader header = zipFile.getFileHeader(name);
        if (header == null) {
            return null;
        }
        dis = new DataInputStream(zipFile.getInputStream(header));
        byte[] data = new byte[(int) header.getUncompressedSize()];
        dis.readFully(data);
        return data;
    } catch (ZipException e) {
        Log.e(TAG, "getResourceBytes: ", e);
    } catch (IOException e) {
        Log.e(TAG, "getResourceBytes: ", e);
    } finally {
        if (dis != null) {
            try {
                dis.close();
            } catch (IOException e) {
                Log.e(TAG, "getResourceBytes: ", e);
            }
        }
    }
    return null;
}
Also used : ZipException(net.lingala.zip4j.exception.ZipException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) File(java.io.File) ZipFile(net.lingala.zip4j.ZipFile) FileHeader(net.lingala.zip4j.model.FileHeader) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ZipException(net.lingala.zip4j.exception.ZipException)

Aggregations

ZipFile (net.lingala.zip4j.ZipFile)12 FileHeader (net.lingala.zip4j.model.FileHeader)6 IOException (java.io.IOException)5 File (java.io.File)4 Path (java.nio.file.Path)3 ZipException (net.lingala.zip4j.exception.ZipException)3 IUser (com.odysseusinc.arachne.portal.model.IUser)2 Submission (com.odysseusinc.arachne.portal.model.Submission)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ZipParameters (net.lingala.zip4j.model.ZipParameters)2 EntityGraph (com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph)1 CommonFileUtils (com.odysseusinc.arachne.commons.utils.CommonFileUtils)1 UUIDGenerator (com.odysseusinc.arachne.commons.utils.UUIDGenerator)1 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)1 UpdateNotificationDTO (com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO)1 WebSecurityConfig (com.odysseusinc.arachne.portal.config.WebSecurityConfig)1 ConverterRuntimeException (com.odysseusinc.arachne.portal.exception.ConverterRuntimeException)1 NoExecutableFileException (com.odysseusinc.arachne.portal.exception.NoExecutableFileException)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1