test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -23,10 +23,12 @@
 
 package com.oracle.java.testlibrary;
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.io.File;
+import java.nio.file.Files;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public final class OutputAnalyzer {

@@ -49,15 +51,33 @@
     this.stderr = output.getStderr();
   }
 
   /**
    * Create an OutputAnalyzer, a utility class for verifying output
+   * loaded from the specified file.
+   *
+   * The loaded output can be retrived with getStdout or/and getOutput
+   * methods, getStderr always returns an empty string.
+   *
+   * @param file a text file to analyze
+   * @throws IOException If an I/O error occurs.
+   **/
+  public OutputAnalyzer(File file) throws IOException {
+      this(new String(Files.readAllBytes(file.toPath())));
+  }
+
+  /**
+   * Create an OutputAnalyzer, a utility class for verifying output
+   * passed as a string.
+   *
+   * The output can be retrived with getStdout or/and getOutput
+   * methods, getStderr always returns an empty string.
    *
    * @param buf String buffer to analyze
    */
   public OutputAnalyzer(String buf) {
-    this(buf, buf);
+      this(buf, "");
   }
 
   /**
    * Create an OutputAnalyzer, a utility class for verifying output
    *