/**
 * Jooby https://jooby.io
 * Apache License Version 2.0 https://jooby.io/LICENSE.txt
 * Copyright 2014 Edgar Espina
 */
package io.jooby.rocker;

import com.fizzed.rocker.RockerModel;
import com.fizzed.rocker.runtime.ArrayOfByteArraysOutput;
import io.jooby.Context;
import io.jooby.MediaType;
import io.jooby.Route;

import javax.annotation.Nonnull;
import java.util.List;

class RockerHandler implements Route.Handler {
  private final Route.Handler next;

  RockerHandler(Route.Handler next) {
    this.next = next;
  }

  @Nonnull @Override public Object apply(@Nonnull Context ctx) throws Exception {
    try {
      RockerModel template = (RockerModel) next.apply(ctx);
      ArrayOfByteArraysOutput buff = template.render(ArrayOfByteArraysOutput.FACTORY);
      List<byte[]> arrays = buff.getArrays();
      ctx.setResponseType(MediaType.html);
      ctx.setResponseLength(buff.getByteLength());
      ctx.send(arrays.toArray(new byte[arrays.size()][]));
      return ctx;
    } catch (Throwable x) {
      ctx.sendError(x);
      return x;
    }
  }
}

@@ -214,33 +214,29 @@
 runtime.
-ArrayOfByteArrays
+StringBuilder
 Output;%0A
@@ -347,31 +347,8 @@
 ull;
-%0Aimport java.util.List;
 %0A%0Acl
@@ -656,284 +656,114 @@
     
-ArrayOfByteArraysOutput buff = template.render(ArrayOfByteArraysOutput.FACTORY);%0A      List%3Cbyte%5B%5D%3E arrays = buff.getArrays();%0A      ctx.setResponseType(MediaType.html);%0A      ctx.setResponseLength(buff.getByteLength());%0A      ctx.send(arrays.toArray(new byte%5Barrays.size()%5D%5B%5D
+ctx.setResponseType(MediaType.html);%0A      ctx.send(template.render(StringBuilderOutput.FACTORY).toString(
 ));%0A

use StringBuilderOutput