diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2018-07-20 07:41:49 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-20 07:43:17 -0700 |
commit | 120b2872287bbbfa8cc870bd0c06c1a4ec6828a5 (patch) | |
tree | 65dd313212286c303042e59ae34a6a3b96ca7472 /src/main/java/com/google/devtools/build/lib/vfs | |
parent | a9c71b4c8a6d8b998c950c35c1e0a697a0d68ffa (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java | 37 |
1 files changed, 4 insertions, 33 deletions
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<String> 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<String> 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); } /** |