Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 90684 invoked from network); 27 Mar 2009 20:10:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Mar 2009 20:10:03 -0000 Received: (qmail 57313 invoked by uid 500); 27 Mar 2009 20:10:02 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 57239 invoked by uid 500); 27 Mar 2009 20:10:02 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 57230 invoked by uid 99); 27 Mar 2009 20:10:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2009 20:10:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2009 20:10:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 76CA92388896; Fri, 27 Mar 2009 20:09:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: tcurdt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090327200941.76CA92388896@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); + + } + }