Search in sources :

Example 31 with ZipFile

use of net.lingala.zip4j.core.ZipFile in project Auto.js by hyb1996.

the class AndroidClassLoader method loadJar.

public void loadJar(File jar) throws IOException {
    try {
        final ZipFile zipFile = new ZipFile(classFile);
        final ZipFile jarFile = new ZipFile(jar);
        // noinspection unchecked
        for (FileHeader header : (List<FileHeader>) jarFile.getFileHeaders()) {
            if (!header.isDirectory()) {
                final ZipParameters parameters = new ZipParameters();
                parameters.setFileNameInZip(header.getFileName());
                parameters.setSourceExternalStream(true);
                zipFile.addStream(jarFile.getInputStream(header), parameters);
            }
        }
        dexJar();
    } catch (ZipException e) {
        IOException exception = new IOException();
        // noinspection UnnecessaryInitCause
        exception.initCause(e);
        throw exception;
    }
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) List(java.util.List) ArrayList(java.util.ArrayList) ZipException(net.lingala.zip4j.exception.ZipException) IOException(java.io.IOException) FileHeader(net.lingala.zip4j.model.FileHeader) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Example 32 with ZipFile

use of net.lingala.zip4j.core.ZipFile in project Auto.js by hyb1996.

the class AndroidClassLoader method defineClass.

/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        final ZipFile zipFile = new ZipFile(classFile);
        final ZipParameters parameters = new ZipParameters();
        parameters.setFileNameInZip(name.replace('.', '/') + ".class");
        parameters.setSourceExternalStream(true);
        zipFile.addStream(new ByteArrayInputStream(data), parameters);
        return dexJar().loadClass(name, parent);
    } catch (IOException | ZipException e) {
        throw new FatalLoadingException(e);
    } finally {
        dexFile.delete();
        odexOatFile.delete();
    }
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipException(net.lingala.zip4j.exception.ZipException) IOException(java.io.IOException) ZipParameters(net.lingala.zip4j.model.ZipParameters)

Example 33 with ZipFile

use of net.lingala.zip4j.core.ZipFile in project codeforces-commons by Codeforces.

the class ZipUtil method getZipArchiveInfo.

public static ZipArchiveInfo getZipArchiveInfo(File zipFile) throws IOException {
    try {
        ZipFile internalZipFile = new ZipFile(zipFile);
        long totalSize = 0;
        long entryCount = 0;
        for (Object fileHeader : internalZipFile.getFileHeaders()) {
            FileHeader entry = (FileHeader) fileHeader;
            long size = entry.getUncompressedSize();
            if (size > 0L) {
                totalSize += size;
            }
            ++entryCount;
        }
        return new ZipArchiveInfo(totalSize, entryCount);
    } catch (ZipException e) {
        throw new IOException("Can't get ZIP-archive info.", e);
    }
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ZipException(net.lingala.zip4j.exception.ZipException) FileHeader(net.lingala.zip4j.model.FileHeader)

Example 34 with ZipFile

use of net.lingala.zip4j.core.ZipFile in project codeforces-commons by Codeforces.

the class ZipUtil method addEntryToZipArchive.

public static void addEntryToZipArchive(File zipFile, String zipEntryPath, InputStream inputStream) throws IOException {
    TFile trueZipFile = new TFile(new File(zipFile, zipEntryPath));
    try {
        OutputStream outputStream = new TFileOutputStream(trueZipFile, false);
        IoUtil.copy(inputStream, outputStream, true, true);
    } finally {
        synchronizeQuietly(trueZipFile);
    }
}
Also used : ByteArrayOutputStream(com.codeforces.commons.io.ByteArrayOutputStream) ZipFile(net.lingala.zip4j.core.ZipFile)

Example 35 with ZipFile

use of net.lingala.zip4j.core.ZipFile in project codeforces-commons by Codeforces.

the class ZipUtil method writeZipEntryBytes.

public static void writeZipEntryBytes(File zipFile, String zipEntryPath, OutputStream outputStream) throws IOException {
    TFile trueZipFile = new TFile(new File(zipFile, zipEntryPath));
    try {
        try {
            InputStream inputStream;
            if (trueZipFile.isArchive()) {
                synchronizeQuietly(trueZipFile);
                ZipFile internalZipFile = new ZipFile(zipFile);
                inputStream = internalZipFile.getInputStream(internalZipFile.getFileHeader(zipEntryPath));
            } else {
                inputStream = new TFileInputStream(trueZipFile);
            }
            IoUtil.copy(inputStream, outputStream);
        } catch (ZipException e) {
            throw new IOException("Can't write ZIP-entry bytes.", e);
        }
    } finally {
        IoUtil.closeQuietly(outputStream);
        synchronizeQuietly(trueZipFile);
    }
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ZipException(net.lingala.zip4j.exception.ZipException) ZipFile(net.lingala.zip4j.core.ZipFile)

Aggregations

ZipFile (net.lingala.zip4j.core.ZipFile)38 File (java.io.File)20 ZipException (net.lingala.zip4j.exception.ZipException)16 ZipParameters (net.lingala.zip4j.model.ZipParameters)13 IOException (java.io.IOException)9 FileHeader (net.lingala.zip4j.model.FileHeader)8 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Nonnull (javax.annotation.Nonnull)4 WorldException (com.voxelgameslib.voxelgameslib.exception.WorldException)3 ByteArrayOutputStream (com.codeforces.commons.io.ByteArrayOutputStream)2 Map (com.voxelgameslib.voxelgameslib.map.Map)2 FileOutputStream (java.io.FileOutputStream)2 FileMeta (org.molgenis.data.file.model.FileMeta)2 CommandPermission (co.aikar.commands.annotation.CommandPermission)1 Subcommand (co.aikar.commands.annotation.Subcommand)1 Syntax (co.aikar.commands.annotation.Syntax)1 com.codeforces.commons.io (com.codeforces.commons.io)1 Math.max (com.codeforces.commons.math.Math.max)1 Patterns (com.codeforces.commons.text.Patterns)1