changeset 957:130caa12e774

runners: clean up System.out intercept logic a bit, future work.
author shade
date Sat, 16 Aug 2014 00:22:19 +0400
parents 8e332f3bc3bf
children e777272ea3e2
files jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Sat Aug 16 00:13:11 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Sat Aug 16 00:22:19 2014 +0400
@@ -102,20 +102,20 @@
         if (options == null) {
             throw new IllegalArgumentException("Options not allowed to be null.");
         }
-        PrintStream out;
-        // setup OutputFormat singleton
+
+        // Intercept the System.out when redirection is requested.
+        // FIXME: We need to properly give up on stream after we are done with it
+        // FIXME: We need to safeguard from accidentally closing the underlying "out"
         if (options.getOutput().hasValue()) {
             try {
-                out = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(options.getOutput().get()))));
+                PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(options.getOutput().get()))));
                 System.setOut(out); // override to print everything to file
             } catch (FileNotFoundException ex) {
                 throw new IllegalStateException(ex);
             }
-        } else {
-            out = System.out;
         }
 
-        return OutputFormatFactory.createFormatInstance(out, options.verbosity().orElse(Defaults.VERBOSITY));
+        return OutputFormatFactory.createFormatInstance(System.out, options.verbosity().orElse(Defaults.VERBOSITY));
     }
 
     /**