commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1649146 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: FileBasedScatterGatherBackingStore.java ParallelScatterZipCreator.java ScatterGatherBackingStore.java ScatterZipOutputStream.java
Date Fri, 02 Jan 2015 22:37:54 GMT
Author: krosenvold
Date: Fri Jan  2 22:37:54 2015
New Revision: 1649146

URL: http://svn.apache.org/r1649146
Log:
Added capability to delete temp files to ScatterGatherBackingStore

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FileBasedScatterGatherBackingStore.java
    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/ScatterGatherBackingStore.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterZipOutputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FileBasedScatterGatherBackingStore.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FileBasedScatterGatherBackingStore.java?rev=1649146&r1=1649145&r2=1649146&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FileBasedScatterGatherBackingStore.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/FileBasedScatterGatherBackingStore.java
Fri Jan  2 22:37:54 2015
@@ -43,11 +43,15 @@ public class FileBasedScatterGatherBacki
     }
 
     @SuppressWarnings("ResultOfMethodCallIgnored")
-    public void close() throws IOException {
+    public void closeForWriting() throws IOException {
         os.close();
     }
 
     public void writeOut(byte[] data, int offset, int length) throws IOException {
         os.write(data, offset, length);
     }
+
+    public void close() throws IOException {
+        target.delete();
+    }
 }

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=1649146&r1=1649145&r2=1649146&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
Fri Jan  2 22:37:54 2015
@@ -20,7 +20,6 @@ package org.apache.commons.compress.arch
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
@@ -29,6 +28,8 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.zip.Deflater;
 
+import static java.util.Collections.synchronizedList;
+
 /**
  * Creates a zip in parallel by using multiple threadlocal #ScatterZipOutputStream instances.
  * <p>
@@ -38,7 +39,8 @@ import java.util.zip.Deflater;
  * #ZipArchiveOutputStream *before* calling #writeTo on this class.</p>
  */
 public class ParallelScatterZipCreator {
-    private List<ScatterZipOutputStream> streams = Collections.synchronizedList(new
ArrayList<ScatterZipOutputStream>());
+    private List<ScatterZipOutputStream> streams = synchronizedList(new ArrayList<ScatterZipOutputStream>());
+    private List<ScatterGatherBackingStore> backingStores = synchronizedList(new ArrayList<ScatterGatherBackingStore>());
     private final ExecutorService es;
     private final ScatterGatherBackingStoreSupplier defaultSupplier;
 
@@ -55,14 +57,14 @@ public class ParallelScatterZipCreator {
         }
     }
 
-    public static ScatterZipOutputStream createDeferred(ScatterGatherBackingStoreSupplier
scatterGatherBackingStoreSupplier)
+    private ScatterZipOutputStream createDeferred(ScatterGatherBackingStoreSupplier scatterGatherBackingStoreSupplier)
             throws IOException {
         ScatterGatherBackingStore bs = scatterGatherBackingStoreSupplier.get();
+        backingStores.add( bs);
         StreamCompressor sc = StreamCompressor.create(Deflater.DEFAULT_COMPRESSION, bs);
         return new ScatterZipOutputStream(bs, sc);
     }
 
-
     private ThreadLocal<ScatterZipOutputStream> tlScatterStreams = new ThreadLocal<ScatterZipOutputStream>()
{
         @Override
         protected ScatterZipOutputStream initialValue() {
@@ -141,7 +143,10 @@ public class ParallelScatterZipCreator {
         }
 
         scatterDoneAt = System.currentTimeMillis();
-        // Maybe close ScatterZipOS. We should do something to get rid of tempfiles.
+
+        for (ScatterGatherBackingStore backingStore : backingStores) {
+            backingStore.close();
+        }
     }
 
     /**

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterGatherBackingStore.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterGatherBackingStore.java?rev=1649146&r1=1649145&r2=1649146&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterGatherBackingStore.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ScatterGatherBackingStore.java
Fri Jan  2 22:37:54 2015
@@ -22,8 +22,12 @@ import java.io.IOException;
 import java.io.InputStream;
 
 /**
- * Abstraction over a scatter-output zip archives can be written to
- * with a method to gather all content from an InputStream later on.
+ * <p></p>Abstraction over a scatter-output zip archives can be written to
+ * with a method to gather all content from an InputStream later on.</p>
+ *
+ * <p>It is the responsibility of the allocator of an instance of this class
+ * to close this. Closing it should clear off any allocated structures
+ * and preferably delete files.</p>
  *
  * @since 1.10
  */
@@ -45,5 +49,10 @@ public interface ScatterGatherBackingSto
      * @param length the amount of data to write
      * @throws IOException when something fails
      */
-    void writeOut(byte[] data, int offset, int length) throws IOException ;
+    void writeOut(byte[] data, int offset, int length) throws IOException;
+
+    /**
+     * Closes this backing store for further writing.
+     */
+    void closeForWriting() throws IOException;
 }

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=1649146&r1=1649145&r2=1649146&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
Fri Jan  2 22:37:54 2015
@@ -100,7 +100,7 @@ public class ScatterZipOutputStream  {
      * @throws IOException If writing fails
      */
     public void writeTo(ZipArchiveOutputStream target) throws IOException {
-        backingStore.close();
+        backingStore.closeForWriting();
         InputStream data = backingStore.getInputStream();
         for (CompressedEntry compressedEntry : items) {
             final BoundedInputStream rawStream = new BoundedInputStream(data, compressedEntry.compressedSize);



Mime
View raw message