Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public synchronized void reset() {
} else {
// Throw away old buffers
currentBuffer = null;
int size = buffers.get(0).length;
int size = buffers.isEmpty() ? 1024 : buffers.get(0).length;
buffers.clear();
needNewBuffer(size);
reuseBuffers = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.SequenceInputStream;
import java.io.UncheckedIOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class ConcurrentJarCreator {

private final ParallelScatterZipCreator parallelScatterZipCreator;

private final ExecutorService es;

private long zipCloseElapsed;

private static class DeferredSupplier implements ScatterGatherBackingStoreSupplier {
Expand Down Expand Up @@ -118,8 +121,8 @@ public ConcurrentJarCreator(boolean compressAddedZips, int nThreads) throws IOEx
manifest = createDeferred(defaultSupplier);
directories = createDeferred(defaultSupplier);
synchronousEntries = createDeferred(defaultSupplier);
parallelScatterZipCreator =
new ParallelScatterZipCreator(Executors.newFixedThreadPool(nThreads), defaultSupplier);
es = Executors.newFixedThreadPool(nThreads);
parallelScatterZipCreator = new ParallelScatterZipCreator(es, defaultSupplier);
}

/**
Expand Down Expand Up @@ -161,11 +164,15 @@ public void addArchiveEntry(

public void writeTo(ZipArchiveOutputStream targetStream)
throws IOException, ExecutionException, InterruptedException {
metaInfDir.writeTo(targetStream);
manifest.writeTo(targetStream);
directories.writeTo(targetStream);
synchronousEntries.writeTo(targetStream);
parallelScatterZipCreator.writeTo(targetStream);
try {
metaInfDir.writeTo(targetStream);
manifest.writeTo(targetStream);
directories.writeTo(targetStream);
synchronousEntries.writeTo(targetStream);
parallelScatterZipCreator.writeTo(targetStream);
} finally {
es.shutdown();
}
long startAt = System.currentTimeMillis();
targetStream.close();
zipCloseElapsed = System.currentTimeMillis() - startAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/
package org.codehaus.plexus.archiver.zip;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.commons.compress.parallel.ScatterGatherBackingStore;

Expand Down Expand Up @@ -48,9 +49,9 @@ public void closeForWriting() throws IOException {

@Override
public void close() throws IOException {
File file = dfos.getFile();
Path file = dfos.getOutputPath();
if (file != null) {
file.delete();
Files.deleteIfExists(file);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected OutputStream getStream() throws IOException {
@Override
protected void thresholdReached() throws IOException {
outputPath = Files.createTempFile(prefix, suffix);
currentOutputStream = Streams.fileOutputStream(outputPath);
currentOutputStream = Streams.bufferedOutputStream(Files.newOutputStream(outputPath));
}

public InputStream getInputStream() throws IOException {
Expand Down Expand Up @@ -142,6 +142,10 @@ public byte[] getData() {
return null;
}

public Path getOutputPath() {
return outputPath;
}

/**
* Returns either the output file specified in the constructor or
* the temporary file created or null.
Expand Down
Loading