org.testcontainers.containers.output.ToStringConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testcontainers Show documentation
Show all versions of testcontainers Show documentation
Isolated container management for Java code testing
The newest version!
package org.testcontainers.containers.output;
import com.google.common.base.Charsets;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* Created by rnorth on 26/03/2016.
*/
public class ToStringConsumer extends BaseConsumer {
private final ByteArrayOutputStream stringBuffer = new ByteArrayOutputStream();
@Override
public void accept(OutputFrame outputFrame) {
try {
final byte[] bytes = outputFrame.getBytes();
if (bytes != null) {
stringBuffer.write(bytes);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String toUtf8String() {
byte[] bytes = stringBuffer.toByteArray();
return new String(bytes, Charsets.UTF_8);
}
public String toString(Charset charset) {
byte[] bytes = stringBuffer.toByteArray();
return new String(bytes, charset);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy