commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1649181 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/
Date Sat, 03 Jan 2015 09:48:46 GMT
Author: krosenvold
Date: Sat Jan  3 09:48:46 2015
New Revision: 1649181

URL: http://svn.apache.org/r1649181
Log:
Cleaned up close semantics of backing store, made this governed by ScatterZipOutputStream

Also added a way to provide a custom supplier

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStream.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java?rev=1649181&r1=1649180&r2=1649181&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
Sat Jan  3 09:48:46 2015
@@ -42,7 +42,7 @@ public class ParallelScatterZipCreator {
     private List<ScatterZipOutputStream> streams = synchronizedList(new ArrayList<ScatterZipOutputStream>());
     private List<ScatterGatherBackingStore> backingStores = synchronizedList(new ArrayList<ScatterGatherBackingStore>());
     private final ExecutorService es;
-    private final ScatterGatherBackingStoreSupplier defaultSupplier;
+    private final ScatterGatherBackingStoreSupplier supplier;
 
     private final long startedAt = System.currentTimeMillis();
     private long compressionDoneAt = 0;
@@ -69,7 +69,7 @@ public class ParallelScatterZipCreator {
         @Override
         protected ScatterZipOutputStream initialValue() {
             try {
-                ScatterZipOutputStream scatterStream = createDeferred(defaultSupplier);
+                ScatterZipOutputStream scatterStream = createDeferred(supplier);
                 streams.add(scatterStream);
                 return scatterStream;
             } catch (IOException e) {
@@ -91,7 +91,17 @@ public class ParallelScatterZipCreator {
      * @param nThreads the number of threads to use in parallel.
      */
     public ParallelScatterZipCreator(int nThreads) {
-        defaultSupplier = new DefaultSupplier();
+        this( nThreads, new DefaultSupplier());
+    }
+
+    /**
+     * Create a ParallelScatterZipCreator
+     *
+     * @param nThreads the number of threads to use in parallel.
+     * @param backingStoreSupplier The supplier of backing store which shall be used
+     */
+    public ParallelScatterZipCreator(int nThreads, ScatterGatherBackingStoreSupplier backingStoreSupplier)
{
+        supplier = backingStoreSupplier;
         es = Executors.newFixedThreadPool(nThreads);
     }
 
@@ -140,6 +150,7 @@ public class ParallelScatterZipCreator {
 
         for (ScatterZipOutputStream scatterStream : streams) {
             scatterStream.writeTo(targetStream);
+            scatterStream.close();
         }
 
         scatterDoneAt = System.currentTimeMillis();

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStream.java?rev=1649181&r1=1649180&r2=1649181&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStream.java
Sat Jan  3 09:48:46 2015
@@ -20,6 +20,7 @@ package org.apache.commons.compress.arch
 
 import org.apache.commons.compress.utils.BoundedInputStream;
 
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -42,7 +43,7 @@ import java.util.zip.Deflater;
  *
  * @since 1.10
  */
-public class ScatterZipOutputStream  {
+public class ScatterZipOutputStream implements Closeable {
     private final Queue<CompressedEntry> items = new ConcurrentLinkedQueue<CompressedEntry>();
     private final ScatterGatherBackingStore backingStore;
     private final StreamCompressor streamCompressor;
@@ -110,6 +111,15 @@ public class ScatterZipOutputStream  {
         data.close();
     }
 
+
+    /**
+     * Closes this stream, freeing all resources involved in the creation of this stream.
+     * @throws IOException If closing fails
+     */
+    public void close() throws IOException {
+        backingStore.close();
+    }
+
     /**
      * Create a ScatterZipOutputStream with default compression level that is backed by a
file
      *

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java?rev=1649181&r1=1649180&r2=1649181&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStreamTest.java
Sat Jan  3 09:48:46 2015
@@ -45,6 +45,7 @@ public class ScatterZipOutputStreamTest
         ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target);
         scatterZipOutputStream.writeTo( outputStream);
         outputStream.close();
+        scatterZipOutputStream.close();
 
         ZipFile zf = new ZipFile(target);
         final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();



Mime
View raw message