|
|
@ -134,7 +134,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
JarArchiveEntry entry = new JarArchiveEntry(entries.nextElement());
|
|
|
|
JarArchiveEntry entry = new JarArchiveEntry(entries.nextElement());
|
|
|
|
setUpEntry(jarFile, entry);
|
|
|
|
setUpEntry(jarFile, entry);
|
|
|
|
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) {
|
|
|
|
try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) {
|
|
|
|
EntryWriter entryWriter = new InputStreamEntryWriter(inputStream, true);
|
|
|
|
EntryWriter entryWriter = new InputStreamEntryWriter(inputStream);
|
|
|
|
JarArchiveEntry transformedEntry = entryTransformer.transform(entry);
|
|
|
|
JarArchiveEntry transformedEntry = entryTransformer.transform(entry);
|
|
|
|
if (transformedEntry != null) {
|
|
|
|
if (transformedEntry != null) {
|
|
|
|
writeEntry(transformedEntry, entryWriter, unpackHandler);
|
|
|
|
writeEntry(transformedEntry, entryWriter, unpackHandler);
|
|
|
@ -163,7 +163,12 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void writeEntry(String entryName, InputStream inputStream) throws IOException {
|
|
|
|
public void writeEntry(String entryName, InputStream inputStream) throws IOException {
|
|
|
|
JarArchiveEntry entry = new JarArchiveEntry(entryName);
|
|
|
|
JarArchiveEntry entry = new JarArchiveEntry(entryName);
|
|
|
|
writeEntry(entry, new InputStreamEntryWriter(inputStream, true));
|
|
|
|
try {
|
|
|
|
|
|
|
|
writeEntry(entry, new InputStreamEntryWriter(inputStream));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
|
|
|
|
inputStream.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -177,8 +182,9 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
JarArchiveEntry entry = new JarArchiveEntry(destination + library.getName());
|
|
|
|
JarArchiveEntry entry = new JarArchiveEntry(destination + library.getName());
|
|
|
|
entry.setTime(getNestedLibraryTime(file));
|
|
|
|
entry.setTime(getNestedLibraryTime(file));
|
|
|
|
new CrcAndSize(file).setupStoredEntry(entry);
|
|
|
|
new CrcAndSize(file).setupStoredEntry(entry);
|
|
|
|
writeEntry(entry, new InputStreamEntryWriter(new FileInputStream(file), true),
|
|
|
|
try (FileInputStream input = new FileInputStream(file)) {
|
|
|
|
new LibraryUnpackHandler(library));
|
|
|
|
writeEntry(entry, new InputStreamEntryWriter(input), new LibraryUnpackHandler(library));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private long getNestedLibraryTime(File file) {
|
|
|
|
private long getNestedLibraryTime(File file) {
|
|
|
@ -221,7 +227,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
JarEntry entry;
|
|
|
|
JarEntry entry;
|
|
|
|
while ((entry = inputStream.getNextJarEntry()) != null) {
|
|
|
|
while ((entry = inputStream.getNextJarEntry()) != null) {
|
|
|
|
if (entry.getName().endsWith(".class")) {
|
|
|
|
if (entry.getName().endsWith(".class")) {
|
|
|
|
writeEntry(new JarArchiveEntry(entry), new InputStreamEntryWriter(inputStream, false));
|
|
|
|
writeEntry(new JarArchiveEntry(entry), new InputStreamEntryWriter(inputStream));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -283,7 +289,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
entryWriter.write(output);
|
|
|
|
entryWriter.write(output);
|
|
|
|
entry.setComment("UNPACK:" + unpackHandler.sha1Hash(entry.getName()));
|
|
|
|
entry.setComment("UNPACK:" + unpackHandler.sha1Hash(entry.getName()));
|
|
|
|
return new InputStreamEntryWriter(new ByteArrayInputStream(output.toByteArray()), true);
|
|
|
|
return new InputStreamEntryWriter(new ByteArrayInputStream(output.toByteArray()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -307,11 +313,8 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
|
|
|
|
|
|
|
|
private final InputStream inputStream;
|
|
|
|
private final InputStream inputStream;
|
|
|
|
|
|
|
|
|
|
|
|
private final boolean close;
|
|
|
|
InputStreamEntryWriter(InputStream inputStream) {
|
|
|
|
|
|
|
|
|
|
|
|
InputStreamEntryWriter(InputStream inputStream, boolean close) {
|
|
|
|
|
|
|
|
this.inputStream = inputStream;
|
|
|
|
this.inputStream = inputStream;
|
|
|
|
this.close = close;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -322,9 +325,6 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
|
|
|
|
outputStream.write(buffer, 0, bytesRead);
|
|
|
|
outputStream.write(buffer, 0, bytesRead);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outputStream.flush();
|
|
|
|
outputStream.flush();
|
|
|
|
if (this.close) {
|
|
|
|
|
|
|
|
this.inputStream.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|