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;
}
}
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();
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations