use of com.android.builder.packaging.ZipAbortException in project atlas by alibaba.
the class JarMergerWithOverride method addJar.
public void addJar(@NonNull File file, boolean removeEntryTimestamp) throws IOException {
logger.verbose("addJar(%1$s)", file);
init();
Closer localCloser = Closer.create();
try {
FileInputStream fis = localCloser.register(new FileInputStream(file));
ZipInputStream zis = localCloser.register(new ZipInputStream(fis));
// loop on the entries of the jar file package and put them in the final jar
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
// do not take directories or anything inside a potential META-INF folder.
if (entry.isDirectory()) {
continue;
}
String name = entry.getName();
if (filter != null && !filter.checkEntry(entry.getName())) {
continue;
}
JarEntry newEntry;
// Preserve the STORED method of the input entry.
if (entry.getMethod() == JarEntry.STORED) {
newEntry = new JarEntry(entry);
} else {
// Create a new entry so that the compressed len is recomputed.
newEntry = new JarEntry(name);
}
if (removeEntryTimestamp) {
newEntry.setTime(0);
}
// add the entry to the jar archive
logger.verbose("addJar(%1$s): entry %2$s", file, name);
duplicates.put(name, file.getAbsolutePath());
if (duplicates.get(name).size() > 1) {
logger.info("[Duplicated]" + name + ":" + file.getAbsolutePath() + ":" + duplicates.get(name));
continue;
}
jarOutputStream.putNextEntry(newEntry);
// read the content of the entry from the input stream, and write it into the archive.
int count;
while ((count = zis.read(buffer)) != -1) {
jarOutputStream.write(buffer, 0, count);
}
// close the entries for this file
jarOutputStream.closeEntry();
zis.closeEntry();
}
} catch (ZipAbortException e) {
throw new IOException("check exception", e);
} finally {
localCloser.close();
}
}
Aggregations