use of com.fizzed.rocker.runtime.ArrayOfByteArraysOutput in project ratpack by ratpack.
the class DefaultRockerRenderer method render.
@Override
public void render(Context context, RockerModel rockerModel) throws Exception {
try {
ArrayOfByteArraysOutput output = rockerModel.render(ArrayOfByteArraysOutput.FACTORY);
List<byte[]> arrays = output.getArrays();
ByteBuf byteBuf;
int size = arrays.size();
if (size == 0) {
byteBuf = Unpooled.EMPTY_BUFFER;
} else if (size == 1) {
byteBuf = Unpooled.wrappedBuffer(arrays.get(0));
} else {
byteBuf = new CompositeByteBuf(UnpooledByteBufAllocator.DEFAULT, false, size, Iterables.transform(arrays, Unpooled::wrappedBuffer));
}
AsciiString contentType = output.getContentType() == ContentType.HTML ? HTML : TEXT;
context.getResponse().contentTypeIfNotSet(contentType).send(byteBuf);
} catch (Exception e) {
// This can be removed when the above issue is rectified.
throw new RendererException("Error rendering template " + rockerModel.getClass().getName(), e);
}
}
Aggregations