From 120b2872287bbbfa8cc870bd0c06c1a4ec6828a5 Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Fri, 20 Jul 2018 07:41:49 -0700 Subject: vfs: do not close streams twice ByteStream's functions already close the underlying stream. See https://github.com/bazelbuild/bazel/commit/09d20311d982606093ed881d779bb05a5ee70ed3 Change-Id: Id389ef594946bfebb90ca66d97ea96f271b20331 Closes #5641. Change-Id: Id389ef594946bfebb90ca66d97ea96f271b20331 PiperOrigin-RevId: 205395805 --- .../devtools/build/lib/vfs/FileSystemUtils.java | 37 +++------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index 4d1e9c6533..e1ac9fb7ae 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -698,14 +698,7 @@ public class FileSystemUtils { */ public static void writeContent(Path outputFile, Charset charset, String content) throws IOException { - try (OutputStream out = outputFile.getOutputStream()) { - new ByteSink() { - @Override - public OutputStream openStream() throws IOException { - return out; - } - }.asCharSink(charset).write(content); - } + asByteSink(outputFile).asCharSink(charset).write(content); } /** @@ -736,14 +729,7 @@ public class FileSystemUtils { public static void writeLinesAs(Path file, Charset charset, Iterable lines) throws IOException { createDirectoryAndParents(file.getParentDirectory()); - try (OutputStream out = file.getOutputStream()) { - new ByteSink() { - @Override - public OutputStream openStream() throws IOException { - return out; - } - }.asCharSink(charset).writeLines(lines); - } + asByteSink(file).asCharSink(charset).writeLines(lines); } /** @@ -754,14 +740,7 @@ public class FileSystemUtils { public static void appendLinesAs(Path file, Charset charset, Iterable lines) throws IOException { createDirectoryAndParents(file.getParentDirectory()); - try (OutputStream out = file.getOutputStream(true)) { - new ByteSink() { - @Override - public OutputStream openStream() throws IOException { - return out; - } - }.asCharSink(charset).writeLines(lines); - } + asByteSink(file, true).asCharSink(charset).writeLines(lines); } /** @@ -770,15 +749,7 @@ public class FileSystemUtils { * @throws IOException if there was an error */ public static void writeContent(Path outputFile, byte[] content) throws IOException { - try (OutputStream out = outputFile.getOutputStream()) { - new ByteSink() { - @Override - public OutputStream openStream() throws IOException { - return out; - } - }.write(content); - ; - } + asByteSink(outputFile).write(content); } /** -- cgit v1.2.3