Skip to content

Commit 3f0c84d

Browse files
committed
Added proper bound on memory usage, patch by Björn Eickvonder
This fixed issue #5
1 parent e42e2cb commit 3f0c84d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/main/java/org/codehaus/plexus/archiver/zip/ConcurrentJarCreator.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
*/
1818
package org.codehaus.plexus.archiver.zip;
1919

20-
import org.apache.commons.compress.archivers.zip.*;
20+
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
21+
import org.apache.commons.compress.archivers.zip.ScatterZipOutputStream;
22+
import org.apache.commons.compress.archivers.zip.StreamCompressor;
23+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
24+
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
2125
import org.apache.commons.compress.parallel.InputStreamSupplier;
2226
import org.apache.commons.compress.parallel.ScatterGatherBackingStore;
2327
import org.apache.commons.compress.parallel.ScatterGatherBackingStoreSupplier;
@@ -42,10 +46,20 @@ public class ConcurrentJarCreator {
4246
private final ParallelScatterZipCreator parallelScatterZipCreator;
4347
private long zipCloseElapsed;
4448

45-
static class DeferredSupplier implements ScatterGatherBackingStoreSupplier
49+
private static class DeferredSupplier
50+
implements ScatterGatherBackingStoreSupplier
4651
{
47-
public ScatterGatherBackingStore get() throws IOException {
48-
return new DeferredScatterOutputStream();
52+
private int threshold;
53+
54+
DeferredSupplier( int threshold )
55+
{
56+
this.threshold = threshold;
57+
}
58+
59+
public ScatterGatherBackingStore get()
60+
throws IOException
61+
{
62+
return new DeferredScatterOutputStream( threshold );
4963
}
5064
}
5165

@@ -57,7 +71,7 @@ public static ScatterZipOutputStream createDeferred(ScatterGatherBackingStoreSup
5771
}
5872

5973
public ConcurrentJarCreator(int nThreads) throws IOException {
60-
ScatterGatherBackingStoreSupplier defaultSupplier = new DeferredSupplier();
74+
ScatterGatherBackingStoreSupplier defaultSupplier = new DeferredSupplier(100000000 / nThreads);
6175

6276
directories = createDeferred(defaultSupplier);
6377
manifest = createDeferred(defaultSupplier);

src/main/java/org/codehaus/plexus/archiver/zip/DeferredScatterOutputStream.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
public class DeferredScatterOutputStream implements ScatterGatherBackingStore
2727
{
28-
OffloadingOutputStream dfos = new OffloadingOutputStream(100000000, "scatterzipfragment", "zip", null);
28+
private final OffloadingOutputStream dfos;
2929

30+
public DeferredScatterOutputStream(int threshold) {
31+
dfos = new OffloadingOutputStream(threshold, "scatterzipfragment", "zip", null);
32+
}
3033

3134
public InputStream getInputStream() throws IOException {
3235
return dfos.getInputStream();

0 commit comments

Comments
 (0)