Search in sources :

Example 1 with LineOrientedOutputStreamRedirector

use of ch.ivyteam.ivy.maven.util.stream.LineOrientedOutputStreamRedirector in project project-build-plugin by axonivy.

the class EngineControl method createEngineLogStreamForwarder.

private PumpStreamHandler createEngineLogStreamForwarder(Consumer<String> logLineHandler) throws FileNotFoundException {
    OutputStream output = getEngineLogTarget();
    OutputStream engineLogStream = new LineOrientedOutputStreamRedirector(output) {

        @Override
        protected void processLine(byte[] b) throws IOException {
            // write file log
            super.processLine(b);
            String line = new String(b);
            context.log.debug("engine: " + line);
            if (logLineHandler != null) {
                logLineHandler.accept(line);
            }
        }
    };
    PumpStreamHandler streamHandler = new PumpStreamHandler(engineLogStream, System.err) {

        @Override
        public void stop() throws IOException {
            super.stop();
            // we opened the stream - we're responsible to close it!
            engineLogStream.close();
        }
    };
    return streamHandler;
}
Also used : PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) LineOrientedOutputStreamRedirector(ch.ivyteam.ivy.maven.util.stream.LineOrientedOutputStreamRedirector)

Aggregations

LineOrientedOutputStreamRedirector (ch.ivyteam.ivy.maven.util.stream.LineOrientedOutputStreamRedirector)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1