All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testcontainers.containers.output.ToStringConsumer Maven / Gradle / Ivy

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