Search in sources :

Example 51 with PrintStream

use of java.io.PrintStream in project CoreNLP by stanfordnlp.

the class BuildLexicalizedParserITest method buildAndTest.

public static void buildAndTest(ParserTestCase test) throws IOException {
    PrintStream originalOut = System.out;
    PrintStream originalErr = System.err;
    System.out.println("Training:");
    System.out.println(StringUtils.join(test.trainCommandLine));
    ByteArrayOutputStream savedOutput = new ByteArrayOutputStream();
    TeeStream teeOut = new TeeStream(savedOutput, System.out);
    PrintStream teeOutPS = new PrintStream(teeOut);
    TeeStream teeErr = new TeeStream(savedOutput, System.err);
    PrintStream teeErrPS = new PrintStream(teeErr);
    System.setOut(teeOutPS);
    System.setErr(teeErrPS);
    LexicalizedParser.main(test.trainCommandLine);
    teeOutPS.flush();
    teeErrPS.flush();
    teeOut.flush();
    teeErr.flush();
    String[] outputLines = savedOutput.toString().split("(?:\\n|\\r)+");
    String perfLine = outputLines[outputLines.length - 5];
    System.out.println(perfLine);
    assertEquals("factor LP/LR summary evalb: LP: 100.0 LR: 100.0 F1: 100.0 Exact: 100.0 N: 1", perfLine.trim());
    Formatter commandLineFormatter = new Formatter();
    commandLineFormatter.format(baseTestSerCommandLine, test.parserFile.getPath(), test.testPath);
    String[] testCommandLine = commandLineFormatter.toString().split("\\s");
    System.out.println("Testing:");
    System.out.println(StringUtils.join(testCommandLine));
    LexicalizedParser.main(testCommandLine);
    commandLineFormatter = new Formatter();
    commandLineFormatter.format(baseTestTextCommandLine, test.textFile.getPath(), test.testPath);
    testCommandLine = commandLineFormatter.toString().split("\\s");
    System.out.println("Testing:");
    System.out.println(StringUtils.join(testCommandLine));
    LexicalizedParser.main(testCommandLine);
    teeOutPS.flush();
    teeErrPS.flush();
    teeOut.flush();
    teeErr.flush();
    System.setOut(originalOut);
    System.setErr(originalErr);
}
Also used : PrintStream(java.io.PrintStream) Formatter(java.util.Formatter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TeeStream(edu.stanford.nlp.io.TeeStream)

Example 52 with PrintStream

use of java.io.PrintStream in project rest.li by linkedin.

the class GeneratorTestUtils method compareFiles.

public static void compareFiles(String actualFileName, String expectedFileName) throws Exception {
    String actual = readFile(actualFileName);
    // exclude the header comment with timestamp
    String actualContent = actual.substring(actual.indexOf("import"));
    String expected = readFile(expectedFileName);
    // exclude the header comment with timestamp
    String expectedContent = expected.substring(expected.indexOf("import"));
    if (!actualContent.trim().equals(expectedContent.trim())) {
        PrintStream actualStdout = new PrintStream(new FileOutputStream(FileDescriptor.out));
        actualStdout.println("ERROR " + actualFileName + " does not match " + expectedFileName + " . Printing diff...");
        try {
            ProcessBuilder pb = new ProcessBuilder("diff", expectedFileName, actualFileName);
            pb.redirectErrorStream();
            Process p = pb.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                actualStdout.println(line);
            }
        } catch (Exception e) {
            actualStdout.println("Error printing diff: " + e.getMessage());
        }
        fail(actualFileName + " does not match " + expectedFileName);
    }
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 53 with PrintStream

use of java.io.PrintStream in project liquibase by liquibase.

the class BaseLiquibaseTask method createPrintStream.

/**
     * @deprecated Subclasses of this class should either instantiate their own output writers or use
     * {@link liquibase.integration.ant.AbstractChangeLogBasedTask} if the task involves a change log.
     */
@Deprecated
public PrintStream createPrintStream() throws IOException {
    if (getOutputFile() == null) {
        return null;
    }
    GlobalConfiguration globalConfiguration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
    String encoding = globalConfiguration.getOutputEncoding();
    return new PrintStream(getOutputFile().getOutputStream(), false, encoding);
}
Also used : PrintStream(java.io.PrintStream) GlobalConfiguration(liquibase.configuration.GlobalConfiguration)

Example 54 with PrintStream

use of java.io.PrintStream in project rest.li by linkedin.

the class GreetingsResourceCodeGenerator method printAll.

private void printAll(final PrintStream out) {
    // print out the main body later
    final ByteArrayOutputStream bodyOutStream = new ByteArrayOutputStream();
    final PrintStream bodyOut = new PrintStream(bodyOutStream);
    printClassHeader(bodyOut);
    bodyOut.println();
    printAllMethods(bodyOut);
    // end class
    bodyOut.println("}");
    // package and imports first
    out.printf("package %s;%n", PACKAGE);
    out.println();
    for (final String c : _importedFull) {
        // don't make import statements for arrays, the base class will be imported separately
        if (!(c.endsWith("[]"))) {
            out.printf("import %s;%n", c);
        }
    }
    out.println();
    // main code body
    out.print(new String(bodyOutStream.toByteArray()));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 55 with PrintStream

use of java.io.PrintStream in project rest.li by linkedin.

the class TestRestLiResourceModelExporter method compareFiles.

private void compareFiles(String actualFileName, String expectedFileName) throws Exception {
    String actualContent = readFile(actualFileName);
    String expectedContent = readFile(expectedFileName);
    if (!actualContent.trim().equals(expectedContent.trim())) {
        // Ugh... gradle
        PrintStream actualStdout = new PrintStream(new FileOutputStream(FileDescriptor.out));
        actualStdout.println("ERROR " + actualFileName + " does not match " + expectedFileName + " . Printing diff...");
        try {
            // TODO environment dependent, not cross platform
            ProcessBuilder pb = new ProcessBuilder("diff", expectedFileName, actualFileName);
            pb.redirectErrorStream();
            Process p = pb.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                actualStdout.println(line);
            //          System.out.println(line);
            }
        } catch (Exception e) {
            // TODO Setup log4j, find appropriate test harness used in R2D2
            actualStdout.println("Error printing diff: " + e.getMessage());
        }
        fail(actualFileName + " does not match " + expectedFileName);
    }
}
Also used : PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Aggregations

PrintStream (java.io.PrintStream)1828 ByteArrayOutputStream (java.io.ByteArrayOutputStream)805 Test (org.junit.Test)583 File (java.io.File)331 IOException (java.io.IOException)295 FileOutputStream (java.io.FileOutputStream)207 ArrayList (java.util.ArrayList)89 FileNotFoundException (java.io.FileNotFoundException)83 OutputStream (java.io.OutputStream)81 Before (org.junit.Before)66 BufferedReader (java.io.BufferedReader)53 BufferedOutputStream (java.io.BufferedOutputStream)49 Map (java.util.Map)49 Date (java.util.Date)46 Path (org.apache.hadoop.fs.Path)42 UnsupportedEncodingException (java.io.UnsupportedEncodingException)41 InputStreamReader (java.io.InputStreamReader)38 Matchers.anyString (org.mockito.Matchers.anyString)38 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)36 List (java.util.List)35