try {
zis = new JarArchiveInputStream(in);
zos = new JarArchiveOutputStream(out);
zos.setLevel(this.level);
XUnclosedInputStream nis = new XUnclosedInputStream(zis);
XUnclosedOutputStream nos = new XUnclosedOutputStream(zos);
Manifest manifest = null;
JarArchiveEntry entry;
JarArchiveEntry jarArchiveEntry;
while((entry = zis.getNextJarEntry()) != null) {
if (!entry.getName().startsWith(XJAR_SRC_DIR) && !entry.getName().endsWith("XJAR-INF/") && !entry.getName().endsWith("XJAR-INF/INDEXES.IDX")) {
if (entry.isDirectory()) {
jarArchiveEntry = new JarArchiveEntry(entry.getName());
jarArchiveEntry.setTime(entry.getTime());
zos.putArchiveEntry(jarArchiveEntry);
} else if (entry.getName().equals("META-INF/MANIFEST.MF")) {
manifest = new Manifest(nis);
Attributes attributes = manifest.getMainAttributes();
String mainClass = attributes.getValue("Main-Class");
if (mainClass != null) {
attributes.putValue("Jar-Main-Class", mainClass);
attributes.putValue("Main-Class", "io.xjar.jar.XJarLauncher");
}
JarArchiveEntry jarArchiveEntry = new JarArchiveEntry(entry.getName());
jarArchiveEntry.setTime(entry.getTime());
zos.putArchiveEntry(jarArchiveEntry);
manifest.write(nos);
} else {
jarArchiveEntry = new JarArchiveEntry(entry.getName());
jarArchiveEntry.setTime(entry.getTime());
zos.putArchiveEntry(jarArchiveEntry);
boolean filtered = this.filtrate(entry);
if (filtered) {
indexes.add(entry.getName());
}
XEncryptor encryptor = filtered ? this.xEncryptor : this.xNopEncryptor;
OutputStream eos = ((XEncryptor)encryptor).encrypt(key, nos);
Throwable var15 = null;
try {
XKit.transfer(nis, eos);
} catch (Throwable var31) {
var15 = var31;
throw var31;
} finally {
if (eos != null) {
if (var15 != null) {
try {
eos.close();
} catch (Throwable var30) {
var15.addSuppressed(var30);
}
} else {
eos.close();
}
}
}
}
zos.closeArchiveEntry();
}
}
if (!indexes.isEmpty()) {
jarArchiveEntry = new JarArchiveEntry("XJAR-INF/");
jarArchiveEntry.setTime(System.currentTimeMillis()); // 当前时间戳
zos.putArchiveEntry(jarArchiveEntry);
zos.closeArchiveEntry();
JarArchiveEntry xjarInfIdx = new JarArchiveEntry("XJAR-INF/INDEXES.IDX");
xjarInfIdx.setTime(System.currentTimeMillis()); // 当前时间戳
zos.putArchiveEntry(xjarInfIdx);
Iterator var39 = indexes.iterator();
while(var39.hasNext()) {
String index = (String)var39.next();
zos.write(index.getBytes());
zos.write(CRLF.getBytes());
}
zos.closeArchiveEntry();
}
String mainClass = manifest != null && manifest.getMainAttributes() != null ? manifest.getMainAttributes().getValue("Main-Class") : null;
if (mainClass != null) {
XInjector.inject(zos);
}
zos.finish();
} finally {
XKit.close(zis);
XKit.close(zos);
}
}