diff --git a/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/server/HadoopServer.java b/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/server/HadoopServer.java index 1454c428310..f7252d504bb 100644 --- a/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/server/HadoopServer.java +++ b/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/server/HadoopServer.java @@ -36,6 +36,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.eclipse.Activator; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.mapred.JobClient; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.JobID; @@ -420,8 +421,14 @@ public class HadoopServer { */ public void storeSettingsToFile(File file) throws IOException { FileOutputStream fos = new FileOutputStream(file); - this.conf.writeXml(fos); - fos.close(); + try { + this.conf.writeXml(fos); + fos.close(); + fos = null; + } finally { + IOUtils.closeStream(fos); + } + } /* @inheritDoc */ diff --git a/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/servers/RunOnHadoopWizard.java b/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/servers/RunOnHadoopWizard.java index 097507f3576..2df29e9c16a 100644 --- a/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/servers/RunOnHadoopWizard.java +++ b/hadoop-mapreduce-project/src/contrib/eclipse-plugin/src/java/org/apache/hadoop/eclipse/servers/RunOnHadoopWizard.java @@ -28,6 +28,7 @@ import org.apache.hadoop.eclipse.Activator; import org.apache.hadoop.eclipse.ErrorMessageDialog; import org.apache.hadoop.eclipse.server.HadoopServer; import org.apache.hadoop.eclipse.server.JarModule; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.mapred.JobConf; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; @@ -164,8 +165,13 @@ public class RunOnHadoopWizard extends Wizard { // confDir); File confFile = new File(confDir, "core-site.xml"); FileOutputStream fos = new FileOutputStream(confFile); - conf.writeXml(fos); - fos.close(); + try { + conf.writeXml(fos); + fos.close(); + fos = null; + } finally { + IOUtils.closeStream(fos); + } } catch (IOException ioe) { ioe.printStackTrace(); diff --git a/hadoop-mapreduce-project/src/contrib/streaming/src/java/org/apache/hadoop/streaming/Environment.java b/hadoop-mapreduce-project/src/contrib/streaming/src/java/org/apache/hadoop/streaming/Environment.java index f8b45f3d06f..bd76c319982 100644 --- a/hadoop-mapreduce-project/src/contrib/streaming/src/java/org/apache/hadoop/streaming/Environment.java +++ b/hadoop-mapreduce-project/src/contrib/streaming/src/java/org/apache/hadoop/streaming/Environment.java @@ -23,6 +23,7 @@ import java.net.InetAddress; import java.util.*; import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.io.IOUtils; /** * This is a class used to get the current environment @@ -62,17 +63,24 @@ public class Environment extends Properties { Process pid = Runtime.getRuntime().exec(command); BufferedReader in = new BufferedReader(new InputStreamReader(pid.getInputStream())); - while (true) { - String line = in.readLine(); - if (line == null) break; - int p = line.indexOf("="); - if (p != -1) { - String name = line.substring(0, p); - String value = line.substring(p + 1); - setProperty(name, value); + try { + while (true) { + String line = in.readLine(); + if (line == null) + break; + int p = line.indexOf("="); + if (p != -1) { + String name = line.substring(0, p); + String value = line.substring(p + 1); + setProperty(name, value); + } } + in.close(); + in = null; + } finally { + IOUtils.closeStream(in); } - in.close(); + try { pid.waitFor(); } catch (InterruptedException e) {