commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1649189 - 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 11:59:56 GMT
Author: krosenvold
Date: Sat Jan  3 11:59:56 2015
New Revision: 1649189

URL: http://svn.apache.org/r1649189
Log:
Cleaned up close semantics further. Increased copy buffer size somewhat

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/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.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=1649189&r1=1649188&r2=1649189&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 11:59:56 2015
@@ -19,6 +19,7 @@ package org.apache.commons.compress.arch
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
@@ -40,7 +41,6 @@ import static java.util.Collections.sync
  */
 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 supplier;
 
@@ -60,7 +60,6 @@ public class ParallelScatterZipCreator {
     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);
     }
@@ -122,7 +121,12 @@ public class ParallelScatterZipCreator {
         es.submit(new Callable<ScatterZipOutputStream>() {
             public ScatterZipOutputStream call() throws Exception {
                 ScatterZipOutputStream streamToUse = tlScatterStreams.get();
-                streamToUse.addArchiveEntry(zipArchiveEntry, source.get(), method);
+                InputStream payload = source.get();
+                try {
+                    streamToUse.addArchiveEntry(zipArchiveEntry, payload, method);
+                } finally {
+                    payload.close();
+                }
                 return streamToUse;
             }
 
@@ -154,10 +158,6 @@ public class ParallelScatterZipCreator {
         }
 
         scatterDoneAt = System.currentTimeMillis();
-
-        for (ScatterGatherBackingStore backingStore : backingStores) {
-            backingStore.close();
-        }
     }
 
     /**

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=1649189&r1=1649188&r2=1649189&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 11:59:56 2015
@@ -82,13 +82,12 @@ public class ScatterZipOutputStream impl
      * Add an archive entry to this scatter stream.
      *
      * @param zipArchiveEntry The entry to write
-     * @param payload         The content to write for the entry
+     * @param payload         The content to write for the entry. The caller is responsible
for closing this.
      * @param method          The compression method
      * @throws IOException    If writing fails
      */
     public void addArchiveEntry(ZipArchiveEntry zipArchiveEntry, InputStream payload, int
method) throws IOException {
         streamCompressor.deflate(payload, method);
-        payload.close();
         items.add(new CompressedEntry(zipArchiveEntry, streamCompressor.getCrc32(),
                                       streamCompressor.getBytesWritten(), method,
                                       streamCompressor.getBytesRead()));

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1649189&r1=1649188&r2=1649189&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Sat Jan  3 11:59:56 2015
@@ -845,7 +845,7 @@ public class ZipArchiveOutputStream exte
 
 
 
-
+    final byte[] copyBuffer = new byte[16384];
 
     private void copyFromZipInputStream(InputStream src) throws IOException {
         if (entry == null) {
@@ -853,11 +853,10 @@ public class ZipArchiveOutputStream exte
         }
         ZipUtil.checkRequestedFeatures(entry.entry);
         entry.hasWritten = true;
-        byte[] tmpBuf = new byte[4096];
         int length;
-        while ((length = src.read( tmpBuf )) >= 0 )
+        while ((length = src.read(copyBuffer)) >= 0 )
         {
-            streamCompressor.writeCounted(tmpBuf, 0, length);
+            streamCompressor.writeCounted(copyBuffer, 0, length);
             count( length );
         }
     }

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=1649189&r1=1649188&r2=1649189&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 11:59:56 2015
@@ -36,10 +36,12 @@ public class ScatterZipOutputStreamTest
         final byte[] A_PAYLOAD = "XAAY".getBytes();
 
         ZipArchiveEntry zab = new ZipArchiveEntry("b.txt");
-        scatterZipOutputStream.addArchiveEntry(zab, new ByteArrayInputStream(B_PAYLOAD),
ZipArchiveEntry.DEFLATED);
+        ByteArrayInputStream payload = new ByteArrayInputStream(B_PAYLOAD);
+        scatterZipOutputStream.addArchiveEntry(zab, payload, ZipArchiveEntry.DEFLATED);
 
         ZipArchiveEntry zae = new ZipArchiveEntry("a.txt");
-        scatterZipOutputStream.addArchiveEntry(zae, new ByteArrayInputStream(A_PAYLOAD),
ZipArchiveEntry.DEFLATED);
+        ByteArrayInputStream payload1 = new ByteArrayInputStream(A_PAYLOAD);
+        scatterZipOutputStream.addArchiveEntry(zae, payload1, ZipArchiveEntry.DEFLATED);
 
         File target = File.createTempFile("scattertest", ".zip");
         ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(target);



Mime
View raw message