org.testcontainers.images.builder.traits.StringsTrait 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
package org.testcontainers.images.builder.traits;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.testcontainers.images.builder.Transferable;
import java.io.IOException;
import java.io.OutputStream;
/**
* BuildContextBuilder's trait for String-based manipulations.
*
*/
public interface StringsTrait & BuildContextBuilderTrait> {
default SELF withFileFromString(String path, String content) {
return ((SELF) this).withFileFromTransferable(path, new Transferable() {
byte[] bytes = content.getBytes();
@Override
public long getSize() {
return bytes.length;
}
@Override
public void transferTo(OutputStream outputStream) {
try {
IOUtils.write(bytes, outputStream);
} catch (IOException e) {
throw new RuntimeException("Can't transfer string " + StringUtils.abbreviate(content, 100), e);
}
}
});
}
}