Search in sources :

Example 21 with ZipException

use of net.lingala.zip4j.exception.ZipException 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 22 with ZipException

use of net.lingala.zip4j.exception.ZipException 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 23 with ZipException

use of net.lingala.zip4j.exception.ZipException 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

ZipException (net.lingala.zip4j.exception.ZipException)23 ZipFile (net.lingala.zip4j.core.ZipFile)15 File (java.io.File)13 ZipParameters (net.lingala.zip4j.model.ZipParameters)9 FileHeader (net.lingala.zip4j.model.FileHeader)8 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ZipFile (net.lingala.zip4j.ZipFile)3 WorldException (com.voxelgameslib.voxelgameslib.exception.WorldException)2 BinaryContent (ddf.catalog.data.BinaryContent)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 ZipFile (java.util.zip.ZipFile)2 HeaderReader (net.lingala.zip4j.core.HeaderReader)2 LocalFileHeader (net.lingala.zip4j.model.LocalFileHeader)2 ZipModel (net.lingala.zip4j.model.ZipModel)2 UnzipEngine (net.lingala.zip4j.unzip.UnzipEngine)2 FileMeta (org.molgenis.data.file.model.FileMeta)2 Content (v7db.files.spi.Content)2