Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 2119 invoked from network); 18 Apr 2011 04:32:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Apr 2011 04:32:39 -0000 Received: (qmail 47223 invoked by uid 500); 18 Apr 2011 04:32:38 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 46968 invoked by uid 500); 18 Apr 2011 04:32:37 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 46959 invoked by uid 99); 18 Apr 2011 04:32:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Apr 2011 04:32:34 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [173.236.76.174] (HELO serv01.siteground309.com) (173.236.76.174) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Apr 2011 04:32:25 +0000 Received: from [96.247.3.234] (port=1716 helo=[192.168.1.2]) by serv01.siteground309.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1QBg83-0004ha-Du for dev@commons.apache.org; Sun, 17 Apr 2011 23:32:03 -0500 Message-ID: <4DABBEC3.9020503@sandglass-software.com> Date: Sun, 17 Apr 2011 21:32:03 -0700 From: Adrian Crum Organization: Sandglass Software User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: dev@commons.apache.org Subject: Re: svn commit: r1094224 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/zip/ZipFile.java References: <20110418042814.F175D23889E3@eris.apache.org> In-Reply-To: <20110418042814.F175D23889E3@eris.apache.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - serv01.siteground309.com X-AntiAbuse: Original Domain - commons.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sandglass-software.com X-Virus-Checked: Checked by ClamAV on apache.org A suggestion: if the library has logging capability, then log a warning saying that the archive was closed in the finalize method. That will serve as a clue to the library user that they forgot to close the archive. -Adrian On 4/17/2011 9:28 PM, bodewig@apache.org wrote: > Author: bodewig > Date: Mon Apr 18 04:28:14 2011 > New Revision: 1094224 > > URL: http://svn.apache.org/viewvc?rev=1094224&view=rev > Log: > add a finalize method to ZipFile as suggested on the user list > > Modified: > commons/proper/compress/trunk/src/changes/changes.xml > commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java > > Modified: commons/proper/compress/trunk/src/changes/changes.xml > URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1094224&r1=1094223&r2=1094224&view=diff > ============================================================================== > --- commons/proper/compress/trunk/src/changes/changes.xml (original) > +++ commons/proper/compress/trunk/src/changes/changes.xml Mon Apr 18 04:28:14 2011 > @@ -45,6 +45,10 @@ The type attribute can be add,u > > > > + > + ZipFile now implements finalize which closes the underlying > + file. > + > > Certain tar files not recognised by ArchiveStreamFactory. > > > Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java > URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1094224&r1=1094223&r2=1094224&view=diff > ============================================================================== > --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java (original) > +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java Mon Apr 18 04:28:14 2011 > @@ -112,6 +112,11 @@ public class ZipFile { > private final boolean useUnicodeExtraFields; > > /** > + * Whether the file is closed. > + */ > + private boolean closed; > + > + /** > * Opens the given file for reading, assuming "UTF8" for file names. > * > * @param f the archive. > @@ -208,8 +213,11 @@ public class ZipFile { > * Closes the archive. > * @throws IOException if an error occurs closing the archive. > */ > - public void close() throws IOException { > - archive.close(); > + public synchronized void close() throws IOException { > + if (!closed) { > + closed = true; > + archive.close(); > + } > } > > /** > @@ -307,6 +315,19 @@ public class ZipFile { > } > } > > + /** > + * Ensures that the close method of this zipfile is called when > + * there are no more references to it. > + * @see close() > + */ > + protected void finalize() throws Throwable { > + try { > + close(); > + } finally { > + super.finalize(); > + } > + } > + > private static final int CFH_LEN = > /* version made by */ SHORT > /* version needed to extract */ + SHORT > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org