You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by js...@apache.org on 2006/05/20 14:29:58 UTC
svn commit: r407990 - in
/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system:
plugin/ repository/ util/
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 {