Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 39741 invoked from network); 20 May 2006 12:30:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 May 2006 12:30:21 -0000 Received: (qmail 79395 invoked by uid 500); 20 May 2006 12:30:21 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 79362 invoked by uid 500); 20 May 2006 12:30:20 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 79351 invoked by uid 99); 20 May 2006 12:30:20 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 May 2006 05:30:20 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 May 2006 05:30:19 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 57ECA1A983A; Sat, 20 May 2006 05:29:59 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r407990 - in /geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system: plugin/ repository/ util/ Date: Sat, 20 May 2006 12:29:58 -0000 To: scm@geronimo.apache.org From: jsisson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060520122959.57ECA1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jsisson Date: Sat May 20 05:29:57 2006 New Revision: 407990 URL: http://svn.apache.org/viewvc?rev=407990&view=rev Log: GERONIMO-2035 [system] ensure input and output streams are closed in finally blocks Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginRepositoryDownloader.java geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/CopyArtifactTypeHandler.java geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/DirectoryInitializationGBean.java Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java?rev=407990&r1=407989&r2=407990&view=diff ============================================================================== --- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java (original) +++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java Sat May 20 05:29:57 2006 @@ -737,19 +737,35 @@ if(in == null) { throw new IllegalStateException(); } - monitor.writeStarted(result.getConfigID().toString(), result.fileSize); - File file = File.createTempFile("geronimo-plugin-download-", ".tmp"); - FileOutputStream out = new FileOutputStream(file); - byte[] buf = new byte[4096]; - int count, total = 0; - while((count = in.read(buf)) > -1) { - out.write(buf, 0, count); - monitor.writeProgress(total += count); + FileOutputStream out = null; + try { + monitor.writeStarted(result.getConfigID().toString(), result.fileSize); + File file = File.createTempFile("geronimo-plugin-download-", ".tmp"); + out = new FileOutputStream(file); + byte[] buf = new byte[4096]; + int count, total = 0; + while((count = in.read(buf)) > -1) { + out.write(buf, 0, count); + monitor.writeProgress(total += count); + } + monitor.writeComplete(total); + in.close(); + in = null; + out.close(); + out = null; + return file; + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException ignored) { } + } + if (out != null) { + try { + out.close(); + } catch (IOException ignored) { } + } } - monitor.writeComplete(total); - in.close(); - out.close(); - return file; } /** Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginRepositoryDownloader.java URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginRepositoryDownloader.java?rev=407990&r1=407989&r2=407990&view=diff ============================================================================== --- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginRepositoryDownloader.java (original) +++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginRepositoryDownloader.java Sat May 20 05:29:57 2006 @@ -21,6 +21,7 @@ import java.util.List; import java.util.ArrayList; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -95,8 +96,9 @@ * Go download a fresh copy of the repository list. */ public void refresh() { + BufferedReader in = null; try { - BufferedReader in = new BufferedReader(new InputStreamReader(repositoryList.openStream())); + in = new BufferedReader(new InputStreamReader(repositoryList.openStream())); String line; List list = new ArrayList(); while((line = in.readLine()) != null) { @@ -106,9 +108,16 @@ } } in.close(); + in = null; kernel.setAttribute(name, "downloadRepositories", list); } catch (Exception e) { log.error("Unable to save download repositories", e); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException ignored) {} + } } } Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java?rev=407990&r1=407989&r2=407990&view=diff ============================================================================== --- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java (original) +++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java Sat May 20 05:29:57 2006 @@ -175,7 +175,16 @@ if (!source.exists() || !source.canRead() || source.isDirectory()) { throw new IllegalArgumentException("Cannot read source file at " + source.getAbsolutePath()); } - copyToRepository(new FileInputStream(source), (int)source.length(), destination, monitor); + FileInputStream is = new FileInputStream(source); + try { + copyToRepository(is, (int)source.length(), destination, monitor); + } finally { + try { + is.close(); + } catch (IOException ignored) { + // ignored + } + } } public void copyToRepository(InputStream source, int size, Artifact destination, FileWriteMonitor monitor) throws IOException { Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/CopyArtifactTypeHandler.java URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/CopyArtifactTypeHandler.java?rev=407990&r1=407989&r2=407990&view=diff ============================================================================== --- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/CopyArtifactTypeHandler.java (original) +++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/CopyArtifactTypeHandler.java Sat May 20 05:29:57 2006 @@ -46,10 +46,12 @@ monitor.writeStarted(artifact.toString(), size); } int total = 0; + BufferedOutputStream out = null; + BufferedInputStream in = null; try { int threshold = TRANSFER_NOTIFICATION_SIZE; - BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(target)); - BufferedInputStream in = new BufferedInputStream(source); + out = new BufferedOutputStream(new FileOutputStream(target)); + in = new BufferedInputStream(source); byte[] buf = new byte[TRANSFER_BUF_SIZE]; int count; while ((count = in.read(buf)) > -1) { @@ -62,10 +64,23 @@ } } } - out.flush(); - out.close(); + out.close(); // also flushes the stream + out = null; in.close(); + in = null; } finally { + if (out != null) { + try { + out.close(); + } catch (IOException ignored) { + } + } + if (in != null) { + try { + in.close(); + } catch (IOException ignored) { + } + } if (monitor != null) { monitor.writeComplete(total); } Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/DirectoryInitializationGBean.java URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/DirectoryInitializationGBean.java?rev=407990&r1=407989&r2=407990&view=diff ============================================================================== --- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/DirectoryInitializationGBean.java (original) +++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/util/DirectoryInitializationGBean.java Sat May 20 05:29:57 2006 @@ -73,7 +73,6 @@ out.write(buf, 0, chunk); } } finally { - out.flush(); out.close(); } } finally {