diff --git a/core/src/main/java/hudson/Main.java b/core/src/main/java/hudson/Main.java
index a3dc3b00cb..3e34cd1427 100644
--- a/core/src/main/java/hudson/Main.java
+++ b/core/src/main/java/hudson/Main.java
@@ -156,14 +156,8 @@ public class Main {
ret = proc.join();
w.write(""+ret+""+(System.currentTimeMillis()-start)+"");
- }
- finally {
- try {
- w.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ } finally {
+ IOUtils.closeQuietly(w);
}
String location = home+"job/"+projectNameEnc+"/postBuildResult";
@@ -183,14 +177,8 @@ public class Main {
FileInputStream in = new FileInputStream(tmpFile);
try {
Util.copyStream(in,con.getOutputStream());
- }
- finally {
- try {
- in.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ } finally {
+ IOUtils.closeQuietly(in);
}
if(con.getResponseCode()!=200) {
diff --git a/core/src/main/java/hudson/console/ConsoleNote.java b/core/src/main/java/hudson/console/ConsoleNote.java
index d36df3c811..639b2106f7 100644
--- a/core/src/main/java/hudson/console/ConsoleNote.java
+++ b/core/src/main/java/hudson/console/ConsoleNote.java
@@ -174,8 +174,7 @@ public abstract class ConsoleNote implements Serializable, Describable implements Serializable, Describable'+getHudsonWar().getAbsolutePath()+'\n');
- }
- finally {
+ } finally {
w.close();
}
}
diff --git a/core/src/main/java/hudson/model/FileParameterValue.java b/core/src/main/java/hudson/model/FileParameterValue.java
index 00e35a44fa..8544042ce4 100644
--- a/core/src/main/java/hudson/model/FileParameterValue.java
+++ b/core/src/main/java/hudson/model/FileParameterValue.java
@@ -205,14 +205,8 @@ public class FileParameterValue extends ParameterValue {
} else {
response.serveFile(request, data, lastModified, contentLength, originalFileName);
}
- }
- finally {
- try {
- data.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ } finally {
+ IOUtils.closeQuietly(data);
}
}
}
diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java
index fba3e653a8..19fa980108 100644
--- a/core/src/main/java/hudson/model/Run.java
+++ b/core/src/main/java/hudson/model/Run.java
@@ -2051,14 +2051,8 @@ public abstract class Run ,RunT extends Run, ExtensionPoint {
} catch (IOException e) {
e.printStackTrace(listener.error(e.getMessage()));
return false;
- }
- finally {
- if (w != null) {
- try {
- w.close();
- } catch (IOException e) {
- // swallow exception
- }
- }
+ } finally {
+ IOUtils.closeQuietly(w);
}
}
diff --git a/core/src/main/java/hudson/tools/JDKInstaller.java b/core/src/main/java/hudson/tools/JDKInstaller.java
index 71ace14f35..40abe42ee7 100644
--- a/core/src/main/java/hudson/tools/JDKInstaller.java
+++ b/core/src/main/java/hudson/tools/JDKInstaller.java
@@ -172,14 +172,8 @@ public class JDKInstaller extends ToolInstaller {
DataInputStream in = new DataInputStream(fs.read(jdkBundle));
try {
in.readFully(header);
- }
- finally {
- try {
- in.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ } finally {
+ IOUtils.closeQuietly(in);
}
}
diff --git a/core/src/main/java/hudson/triggers/SCMTrigger.java b/core/src/main/java/hudson/triggers/SCMTrigger.java
index df8c286e62..0f140bf91b 100644
--- a/core/src/main/java/hudson/triggers/SCMTrigger.java
+++ b/core/src/main/java/hudson/triggers/SCMTrigger.java
@@ -31,6 +31,7 @@ import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Cause;
+import hudson.util.IOUtils;
import jenkins.model.Jenkins;
import hudson.model.Item;
import hudson.model.Project;
@@ -324,14 +325,8 @@ public class SCMTrigger extends Trigger {
FlushProofOutputStream out = new FlushProofOutputStream(rsp.getCompressedOutputStream(req));
try {
getPollingLogText().writeLogTo(0, out);
- }
- finally {
- try {
- out.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ } finally {
+ IOUtils.closeQuietly(out);
}
}
diff --git a/core/src/main/java/hudson/util/CompressedFile.java b/core/src/main/java/hudson/util/CompressedFile.java
index 8938f3276e..f3a9133588 100644
--- a/core/src/main/java/hudson/util/CompressedFile.java
+++ b/core/src/main/java/hudson/util/CompressedFile.java
@@ -120,14 +120,8 @@ public class CompressedFile {
int len;
while((len=r.read(buf,0,buf.length))>0)
str.append(buf,0,len);
- }
- finally {
- try {
- r.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ } finally {
+ IOUtils.closeQuietly(r);
}
return str.toString();
diff --git a/core/src/main/java/hudson/util/TextFile.java b/core/src/main/java/hudson/util/TextFile.java
index 2d804a7ebe..f010f12e1a 100644
--- a/core/src/main/java/hudson/util/TextFile.java
+++ b/core/src/main/java/hudson/util/TextFile.java
@@ -86,18 +86,7 @@ public class TextFile {
w.write(text);
w.commit();
} finally {
- try {
- w.abort();
- }
- catch (IOException ioe) {
- // swallow exception
- }
- try {
- w.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
+ w.abort();
}
}
diff --git a/core/src/main/java/hudson/util/io/ZipArchiver.java b/core/src/main/java/hudson/util/io/ZipArchiver.java
index 2e539ab880..ef0ae49658 100644
--- a/core/src/main/java/hudson/util/io/ZipArchiver.java
+++ b/core/src/main/java/hudson/util/io/ZipArchiver.java
@@ -72,10 +72,9 @@ final class ZipArchiver extends Archiver {
FileInputStream in = new FileInputStream(f);
try {
int len;
- while((len=in.read(buf))>0)
+ while((len=in.read(buf))>=0)
zip.write(buf,0,len);
- }
- finally {
+ } finally {
in.close();
}
zip.closeEntry();
diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java
index 1a16d0b35b..dae24c69df 100755
--- a/core/src/main/java/jenkins/model/Jenkins.java
+++ b/core/src/main/java/jenkins/model/Jenkins.java
@@ -176,6 +176,7 @@ import hudson.util.FormValidation;
import hudson.util.Futures;
import hudson.util.HudsonIsLoading;
import hudson.util.HudsonIsRestarting;
+import hudson.util.IOUtils;
import hudson.util.Iterators;
import hudson.util.JenkinsReloadFailed;
import hudson.util.Memoizer;
@@ -3928,16 +3929,8 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro
props.load(is);
} catch (IOException e) {
e.printStackTrace(); // if the version properties is missing, that's OK.
- }
- finally {
- if (is != null) {
- try {
- is.close();
- }
- catch (IOException ioe) {
- // swallow exception
- }
- }
+ } finally {
+ IOUtils.closeQuietly(is);
}
String ver = props.getProperty("version");
if(ver==null) ver="?";
diff --git a/core/src/main/java/jenkins/model/PeepholePermalink.java b/core/src/main/java/jenkins/model/PeepholePermalink.java
index d36ab3f86f..b4667d32a9 100644
--- a/core/src/main/java/jenkins/model/PeepholePermalink.java
+++ b/core/src/main/java/jenkins/model/PeepholePermalink.java
@@ -178,18 +178,7 @@ public abstract class PeepholePermalink extends Permalink implements Predicate