Java Code Examples for org.testcontainers.containers.output.OutputFrame#getType()

The following examples show how to use org.testcontainers.containers.output.OutputFrame#getType() . 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: PrintingLogConsumer.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public void accept(OutputFrame outputFrame)
{
    // Sanitize message. This mimics code in org.testcontainers.containers.output.Slf4jLogConsumer#accept
    String message = outputFrame.getUtf8String().replaceAll("\\r?\\n?$", "");
    if (message.contains("\n")) {
        log.warn("Message contains newline character: [%s]", message);
    }

    if (!message.isEmpty() || outputFrame.getType() != END) {
        out.println(prefix + message);
    }
    if (outputFrame.getType() == END) {
        out.println(prefix + "(exited)");
    }
    out.flush();
}
 
Example 2
Source File: StandardOutLogConsumer.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@Override
public void accept(OutputFrame outputFrame) {
    if (outputFrame != null) {
        String utf8String = outputFrame.getUtf8String();

        if (utf8String != null) {
            OutputFrame.OutputType outputType = outputFrame.getType();
            String message = utf8String.trim();

            if (ANSI_CODE_PATTERN.matcher(message).matches()) {
                return;
            }

            switch (outputType) {
                case END:
                    break;
                case STDOUT:
                case STDERR:
                    System.out.println(String.format("%s%s", prefix, message));
                    break;
                default:
                    throw new IllegalArgumentException("Unexpected outputType " + outputType);
            }
        }
    }
}