diff options
author | 2015-04-24 14:06:40 +0000 | |
---|---|---|
committer | 2015-04-27 18:46:32 +0000 | |
commit | da2f0ba8109529ad142803334de3ca222bf2d8a6 (patch) | |
tree | 6c67cc6de5a33fe51d8e91e66520d442c4c288f8 /src/main | |
parent | d55ea1e0a22d4fed45000aecaaaafc7d54f1e5c3 (diff) |
Clean up the TestFileOutErr to be less brittle, avoiding the "brutal overloading" it had been doing previously.
--
MOS_MIGRATED_REVID=91979641
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/util/io/FileOutErr.java | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/io/FileOutErr.java b/src/main/java/com/google/devtools/build/lib/util/io/FileOutErr.java index de1087957b..5215c91c69 100644 --- a/src/main/java/com/google/devtools/build/lib/util/io/FileOutErr.java +++ b/src/main/java/com/google/devtools/build/lib/util/io/FileOutErr.java @@ -19,7 +19,6 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -49,7 +48,7 @@ public class FileOutErr extends OutErr { * @param stderr The file for the stderr of this outErr */ public FileOutErr(Path stdout, Path stderr) { - super(new FileRecordingOutputStream(stdout), new FileRecordingOutputStream(stderr)); + this(new FileRecordingOutputStream(stdout), new FileRecordingOutputStream(stderr)); } /** @@ -65,6 +64,11 @@ public class FileOutErr extends OutErr { this(new FileRecordingOutputStream(output)); } + protected FileOutErr(AbstractFileRecordingOutputStream out, + AbstractFileRecordingOutputStream err) { + super(out, err); + } + /** * Creates a new FileOutErr that discards its input. Useful * for testing purposes. @@ -286,13 +290,13 @@ public class FileOutErr extends OutErr { * FileOutErr. */ @ThreadSafety.ThreadCompatible - private static class FileRecordingOutputStream extends AbstractFileRecordingOutputStream { + protected static class FileRecordingOutputStream extends AbstractFileRecordingOutputStream { private final Path outputFile; - OutputStream outputStream; - String error; + private OutputStream outputStream; + private String error; - FileRecordingOutputStream(Path outputFile) { + protected FileRecordingOutputStream(Path outputFile) { this.outputFile = outputFile; } @@ -328,7 +332,7 @@ public class FileOutErr extends OutErr { /** * Called whenever the FileRecordingOutputStream finds an error. */ - private void recordError(IOException exception) { + protected void recordError(IOException exception) { String newErrorText = exception.getMessage(); error = (error == null) ? newErrorText : error + "\n" + newErrorText; } @@ -368,22 +372,14 @@ public class FileOutErr extends OutErr { @Override void dumpOut(OutputStream out) { - InputStream in = null; try { if (getFile().exists()) { - in = new FileInputStream(getFile().getPathString()); - ByteStreams.copy(in, out); + try (InputStream in = getFile().getInputStream()) { + ByteStreams.copy(in, out); + } } } catch (IOException ex) { recordError(ex); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - // Ignore. - } - } } if (hadError()) { |