Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 71677 invoked from network); 27 Apr 2009 17:58:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Apr 2009 17:58:27 -0000 Received: (qmail 87112 invoked by uid 500); 27 Apr 2009 17:58:27 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 87048 invoked by uid 500); 27 Apr 2009 17:58:27 -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 87039 invoked by uid 99); 27 Apr 2009 17:58:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2009 17:58:27 +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; Mon, 27 Apr 2009 17:58:26 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1999723889DE; Mon, 27 Apr 2009 17:58:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r769070 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers: ar/ArArchiveOutputStream.java cpio/CpioArchiveOutputStream.java tar/TarArchiveOutputStream.java zip/ZipArchiveOutputStream.java Date: Mon, 27 Apr 2009 17:58:04 -0000 To: commits@commons.apache.org From: grobmeier@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090427175805.1999723889DE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: grobmeier Date: Mon Apr 27 17:58:04 2009 New Revision: 769070 URL: http://svn.apache.org/viewvc?rev=769070&view=rev Log: only write and close is allowed after the call of finish Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java Mon Apr 27 17:58:04 2009 @@ -53,6 +53,9 @@ } public void closeArchiveEntry() throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } if (prevEntry != null && haveUnclosedEntry && (entryOffset % 2) != 0) { out.write('\n'); // Pad byte archiveOffset++; @@ -61,6 +64,10 @@ } public void putArchiveEntry( final ArchiveEntry pEntry ) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } + ArArchiveEntry pArEntry = (ArArchiveEntry)pEntry; if (prevEntry == null) { archiveOffset += writeArchiveHeader(); @@ -166,6 +173,9 @@ public ArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } return new ArArchiveEntry(inputFile, entryName); } Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java Mon Apr 27 17:58:04 2009 @@ -143,6 +143,10 @@ * @throws ClassCastException if entry is not an instance of CpioArchiveEntry */ public void putArchiveEntry(ArchiveEntry entry) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } + CpioArchiveEntry e = (CpioArchiveEntry) entry; ensureOpen(); if (this.entry != null) { @@ -244,6 +248,10 @@ * () */ public void closeArchiveEntry() throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } + ensureOpen(); if (this.entry.getSize() != this.written) { @@ -400,6 +408,9 @@ */ public ArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } return new CpioArchiveEntry(inputFile, entryName); } Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=769070&r1=769069&r2=769070&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Mon Apr 27 17:58:04 2009 @@ -165,6 +165,9 @@ * @throws ClassCastException if archiveEntry is not an instance of TarArchiveEntry */ public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } TarArchiveEntry entry = (TarArchiveEntry) archiveEntry; if (entry.getName().length() >= TarConstants.NAMELEN) { @@ -212,6 +215,9 @@ * @throws IOException on error */ public void closeArchiveEntry() throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } if (assemLen > 0) { for (int i = assemLen; i < assemBuf.length; ++i) { assemBuf[i] = 0; @@ -332,6 +338,9 @@ public ArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } return new TarArchiveEntry(inputFile, entryName); } } 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=769070&r1=769069&r2=769070&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 Mon Apr 27 17:58:04 2009 @@ -62,8 +62,8 @@ private static final int WORD = 4; static final int BUFFER_SIZE = 512; - /** indicates if this archive is finished */ - private boolean finished = false; + /** indicates if this archive is finished. protected for use in Jar implementation */ + protected boolean finished = false; /* * Apparently Deflater.setInput gets slowed down a lot on Sun JVMs @@ -227,8 +227,7 @@ /** * whether to create UnicodePathExtraField-s for each entry. */ - private UnicodeExtraFieldPolicy createUnicodeExtraFields = - UnicodeExtraFieldPolicy.NEVER; + private UnicodeExtraFieldPolicy createUnicodeExtraFields = UnicodeExtraFieldPolicy.NEVER; /** * Creates a new ZIP OutputStream filtering the underlying stream. @@ -360,6 +359,10 @@ * @throws IOException on error */ public void closeArchiveEntry() throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } + if (entry == null) { return; } @@ -423,6 +426,10 @@ /** {@inheritDoc} */ // @throws ClassCastException if entry is not an instance of ZipArchiveEntry public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } + closeArchiveEntry(); entry = ((ZipArchiveEntry) archiveEntry); @@ -901,13 +908,11 @@ /** * Always create Unicode extra fields. */ - public static final UnicodeExtraFieldPolicy ALWAYS = - new UnicodeExtraFieldPolicy("always"); + public static final UnicodeExtraFieldPolicy ALWAYS = new UnicodeExtraFieldPolicy("always"); /** * Never create Unicode extra fields. */ - public static final UnicodeExtraFieldPolicy NEVER = - new UnicodeExtraFieldPolicy("never"); + public static final UnicodeExtraFieldPolicy NEVER = new UnicodeExtraFieldPolicy("never"); /** * Create Unicode extra fields for filenames that cannot be * encoded using the specified encoding. @@ -926,6 +931,9 @@ public ArchiveEntry createArchiveEntry(File inputFile, String entryName) throws IOException { + if(finished) { + throw new IOException("Stream has already been finished"); + } return new ZipArchiveEntry(inputFile, entryName); } }