aQute.junit.Tee Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.tester Show documentation
Show all versions of biz.aQute.tester Show documentation
A bnd tester. If this bundle is used as the tester (previously aQute.junit) then it will add itself to the -runbundles at the end. At startup, this bundle will then run the tests. This bundle does NOT contain JUnit itself. It will import JUnit just like any other bundle.
package aQute.junit;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
public class Tee extends OutputStream {
PrintStream oldStream;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
boolean capture;
boolean echo;
public Tee(PrintStream oldOut) {
oldStream = oldOut;
}
public PrintStream getStream() {
return new PrintStream(this);
}
@Override
public void write(int character) throws IOException {
if (capture)
buffer.write(character);
if (echo)
oldStream.write(character);
}
public String getContent() {
if (buffer.size() == 0)
return null;
try {
return buffer.toString(Charset.defaultCharset().toString());
} catch (UnsupportedEncodingException e) {
return null;
}
}
public Tee clear() {
buffer.reset();
return this;
}
public Tee capture(boolean capture) {
this.capture = capture;
return this;
}
public Tee echo(boolean echo) {
this.echo = echo;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy