commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r759326 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
Date Fri, 27 Mar 2009 20:09:41 GMT
Author: tcurdt
Date: Fri Mar 27 20:09:40 2009
New Revision: 759326

URL: http://svn.apache.org/viewvc?rev=759326&view=rev
Log:
reproduce https://issues.apache.org/jira/browse/COMPRESS-11


Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java?rev=759326&r1=759325&r2=759326&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
Fri Mar 27 20:09:40 2009
@@ -18,18 +18,20 @@
  */
 package org.apache.commons.compress.archivers;
 
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
 import org.apache.commons.compress.utils.IOUtils;
 
-import org.apache.commons.compress.AbstractTestCase;
-
 public final class ArTestCase extends AbstractTestCase {
+
 	public void testArArchiveCreation() throws Exception {
 		final File output = new File(dir, "bla.ar");
 		
@@ -71,7 +73,7 @@
 		// UnArArchive Operation
 		final File input = output;
 		final InputStream is = new FileInputStream(input);
-		final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("ar",
is);
+		final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is));
 		final ArArchiveEntry entry = (ArArchiveEntry)in.getNextEntry();
 		
 		File target = new File(dir, entry.getName());
@@ -84,4 +86,74 @@
         is.close();
 	}
 
+	public void testArDelete() throws Exception {
+		final File output = new File(dir, "bla.ar");
+		
+		{
+			// create
+			final File file1 = getFile("test1.xml");
+			final File file2 = getFile("test2.xml");
+			
+			final OutputStream out = new FileOutputStream(output);
+	        final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("ar",
out);
+			os.putArchiveEntry(new ArArchiveEntry("test1.xml", file1.length()));
+			IOUtils.copy(new FileInputStream(file1), os);
+			os.closeArchiveEntry();
+			
+			os.putArchiveEntry(new ArArchiveEntry("test2.xml", file2.length()));
+			IOUtils.copy(new FileInputStream(file2), os);
+			os.closeArchiveEntry();
+			os.close();
+			out.close();
+		}
+		
+		final File output2 = new File(dir, "bla2.ar");		
+
+		{
+			// remove all but one file
+			final InputStream is = new FileInputStream(output);
+			final OutputStream os = new FileOutputStream(output2);
+			final ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("ar",
os);
+			final ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(new
BufferedInputStream(is));
+			while(true) {
+				final ArArchiveEntry entry = (ArArchiveEntry)ais.getNextEntry();
+				if (entry == null) {
+					break;
+				}
+				
+				if ("test1.xml".equals(entry.getName())) {
+					aos.putArchiveEntry(entry);
+				}
+			}
+			ais.close();
+			aos.close();
+			is.close();
+			os.close();			
+		}
+
+		
+		long sum = 0;
+
+		{
+			final InputStream is = new FileInputStream(output2);
+			final ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(is);
+			while(true) {
+				final ArArchiveEntry entry = (ArArchiveEntry)ais.getNextEntry();
+				if (entry == null) {
+					break;
+				}
+				
+				final ByteArrayOutputStream os = new ByteArrayOutputStream();
+		        IOUtils.copy(ais, os);
+		        
+		        sum +=  entry.getLength();
+			}
+			ais.close();
+			is.close();			
+		}
+
+		assertEquals(0, sum);
+		
+	}
+
 }



Mime
View raw message