|
28 | 28 | import java.util.zip.Deflater;
|
29 | 29 | import java.util.zip.ZipEntry;
|
30 | 30 |
|
| 31 | +import static org.apache.commons.compress.archivers.zip.ZipArchiveEntryRequest.createZipArchiveEntryRequest; |
| 32 | + |
31 | 33 | public class ConcurrentJarCreator {
|
32 | 34 |
|
33 | 35 | private final ScatterZipOutputStream directories;
|
@@ -72,18 +74,27 @@ public void addArchiveEntry(final ZipArchiveEntry zipArchiveEntry, final InputSt
|
72 | 74 | final int method = zipArchiveEntry.getMethod();
|
73 | 75 | if (method == -1) throw new IllegalArgumentException("Method must be set on the supplied zipArchiveEntry");
|
74 | 76 | if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) {
|
75 |
| - ByteArrayInputStream payload = new ByteArrayInputStream(new byte[]{}); |
76 |
| - directories.addArchiveEntry(zipArchiveEntry, payload, ZipEntry.STORED); |
| 77 | + final ByteArrayInputStream payload = new ByteArrayInputStream(new byte[]{}); |
| 78 | + directories.addArchiveEntry(createZipArchiveEntryRequest(zipArchiveEntry, createInputStreamSupplier(payload))); |
77 | 79 | payload.close();
|
78 | 80 | } else if ("META-INF".equals(zipArchiveEntry.getName()) || "META-INF/MANIFEST.MF".equals(zipArchiveEntry.getName())) {
|
79 | 81 | InputStream payload = source.get();
|
80 |
| - manifest.addArchiveEntry(zipArchiveEntry, payload, zipArchiveEntry.isDirectory() ? ZipEntry.STORED : method); |
| 82 | + if (zipArchiveEntry.isDirectory()) zipArchiveEntry.setMethod(ZipEntry.STORED); |
| 83 | + manifest.addArchiveEntry(createZipArchiveEntryRequest(zipArchiveEntry, createInputStreamSupplier(payload))); |
81 | 84 | payload.close();
|
82 | 85 | } else {
|
83 | 86 | parallelScatterZipCreator.addArchiveEntry(zipArchiveEntry, source);
|
84 | 87 | }
|
85 | 88 | }
|
86 | 89 |
|
| 90 | + private InputStreamSupplier createInputStreamSupplier(final InputStream payload) { |
| 91 | + return new InputStreamSupplier() { |
| 92 | + public InputStream get() { |
| 93 | + return payload; |
| 94 | + } |
| 95 | + }; |
| 96 | + } |
| 97 | + |
87 | 98 | public void writeTo(ZipArchiveOutputStream targetStream) throws IOException, ExecutionException, InterruptedException {
|
88 | 99 | manifest.writeTo(targetStream);
|
89 | 100 | directories.writeTo(targetStream);
|
|
0 commit comments