From 26cdffc7519298f50b1965ac38a749159cbcc2e4 Mon Sep 17 00:00:00 2001 From: lvotypko Date: Tue, 17 May 2016 13:44:28 +0200 Subject: [PATCH] Close file after reading. --- .../FileBuildParameters.java | 2 +- .../ParameterizedTriggerUtils.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/parameterizedtrigger/FileBuildParameters.java b/src/main/java/hudson/plugins/parameterizedtrigger/FileBuildParameters.java index c3739cbe..f4defe4c 100644 --- a/src/main/java/hudson/plugins/parameterizedtrigger/FileBuildParameters.java +++ b/src/main/java/hudson/plugins/parameterizedtrigger/FileBuildParameters.java @@ -118,7 +118,7 @@ private List extractAllValues(AbstractBuild build, TaskList String s = null; VirtualFile artifact = build.getArtifactManager().root().child(file); if (artifact.isFile()) { - s = IOUtils.toString(artifact.open()); + s = ParameterizedTriggerUtils.readFileToString(artifact); } if (s == null) { diff --git a/src/main/java/hudson/plugins/parameterizedtrigger/ParameterizedTriggerUtils.java b/src/main/java/hudson/plugins/parameterizedtrigger/ParameterizedTriggerUtils.java index af8087f0..76734ba6 100644 --- a/src/main/java/hudson/plugins/parameterizedtrigger/ParameterizedTriggerUtils.java +++ b/src/main/java/hudson/plugins/parameterizedtrigger/ParameterizedTriggerUtils.java @@ -34,6 +34,7 @@ import java.io.StringReader; import java.util.LinkedHashMap; import java.util.Properties; +import jenkins.util.VirtualFile; /** * Common utility methods. @@ -67,6 +68,22 @@ public static String readFileToString(FilePath f, String encoding) throws IOExce } } + /** + * {@link read VirtualFile + * + * @param f file to read + * @return read string + * @throws IOException + */ + public static String readFileToString(VirtualFile f) throws IOException, InterruptedException { + InputStream in = f.open(); + try { + return IOUtils.toString(in); + } finally { + in.close(); + } + } + public static ParametersAction mergeParameters(ParametersAction base, ParametersAction overlay) { LinkedHashMap params = new LinkedHashMap(); for (ParameterValue param : base.getParameters())