org.zeroturnaround.exec.stream.LogOutputStream Java Examples

The following examples show how to use org.zeroturnaround.exec.stream.LogOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogOutputStreamTest.java    From zt-exec with Apache License 2.0 6 votes vote down vote up
private void testLogOutputStream(String multiLineString, String... expectedLines) throws UnsupportedEncodingException, IOException {
	final List<String> processedLines = new ArrayList<String>();
	LogOutputStream logOutputStream = new LogOutputStream() {

		@Override
		protected void processLine(String line) {
			processedLines.add(line);
		}
	};
	try {
		logOutputStream.write(multiLineString.getBytes("UTF-8"));
	} finally {
		logOutputStream.close();
	}
	Assert.assertEquals(Arrays.asList(expectedLines), processedLines);
}
 
Example #2
Source File: ReadmeExamples.java    From zt-exec with Apache License 2.0 5 votes vote down vote up
void pumpOutputToLogStream(OutputStream out) throws Exception {
  new ProcessExecutor().command("java", "-version")
      .redirectOutput(new LogOutputStream() {
        @Override
        protected void processLine(String line) {
          // ...
        }
      })
      .execute();
}