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);
}
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);
}
}
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);
}
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()));
}
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);
}
}
Aggregations