Repository: commons-compress
Updated Branches:
  refs/heads/master 1e0957d57 -> d9fe818ee


also compare file contents, patch by Maciej N


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/d9fe818e
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/d9fe818e
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/d9fe818e

Branch: refs/heads/master
Commit: d9fe818eef0003afe295e6e6df112257cffbc88f
Parents: 1e0957d
Author: Stefan Bodewig <bode...@apache.org>
Authored: Sat Oct 15 15:42:54 2016 +0200
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Sat Oct 15 15:42:54 2016 +0200

----------------------------------------------------------------------
 .../commons/compress/archivers/ZipTestCase.java | 32 ++++++++++----------
 1 file changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d9fe818e/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java 
b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
index 84297ae..24fccf6 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.io.InputStream;    
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.zip.ZipEntry;
@@ -110,7 +111,7 @@ public final class ZipTestCase extends AbstractTestCase {
     }
 
     /**
-     * Archives 2 files and unarchives it again. If the file length of result
+     * Archives 2 files and unarchives it again. If the file contents of result
      * and source is the same, it looks like the operations have worked
      * @throws Exception
      */
@@ -118,39 +119,38 @@ public final class ZipTestCase extends AbstractTestCase {
     public void testZipArchiveCreationInMemory() throws Exception {
         final File file1 = getFile("test1.xml");
         final File file2 = getFile("test2.xml");
+        final byte[] file1Contents = new byte[(int) file1.length()];
+        final byte[] file2Contents = new byte[(int) file2.length()];
+        IOUtils.readFully(new FileInputStream(file1), file1Contents);
+        IOUtils.readFully(new FileInputStream(file2), file2Contents);
+
         SeekableInMemoryByteChannel c = new SeekableInMemoryByteChannel();
         try (ZipArchiveOutputStream os = new ZipArchiveOutputStream(c)) {
             os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
-            IOUtils.copy(new FileInputStream(file1), os);
+            os.write(file1Contents);
             os.closeArchiveEntry();
 
             os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml"));
-            IOUtils.copy(new FileInputStream(file2), os);
+            os.write(file2Contents);
             os.closeArchiveEntry();
         }
 
         // Unarchive the same
-        final List<File> results = new ArrayList<>();
+        final List<byte[]> results = new ArrayList<>();
 
         try (ArchiveInputStream in = new ArchiveStreamFactory()
              .createArchiveInputStream("zip", new 
ByteArrayInputStream(c.array()))) {
 
-            ZipArchiveEntry entry = null;
+            ZipArchiveEntry entry;
             while((entry = (ZipArchiveEntry)in.getNextEntry()) != null) {
-                final File outfile = new File(resultDir.getCanonicalPath() + 
"/result/" + entry.getName());
-                outfile.getParentFile().mkdirs();
-                try (OutputStream o = new FileOutputStream(outfile)) {
-                    IOUtils.copy(in, o);
-                }
-                results.add(outfile);
+                byte[] result = new byte[(int) entry.getSize()];
+                IOUtils.readFully(in, result);
+                results.add(result);
             }
         }
 
-        assertEquals(results.size(), 2);
-        File result = results.get(0);
-        assertEquals(file1.length(), result.length());
-        result = results.get(1);
-        assertEquals(file2.length(), result.length());
+        assertArrayEquals(results.get(0), file1Contents);
+        assertArrayEquals(results.get(1), file2Contents);
     }
 
     /**

Reply via email to