code: @Override
      public void writeTo(T templateReference, Viewable viewable, MediaType mediaType,
                          MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException {
          MediaType m = (MediaType) httpHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
          if (m == null) m = mediaType;
          setContentType(m, httpHeaders);
          try {
              writeTemplate(templateReference, viewable, mediaType, httpHeaders, out);
          } catch (Exception e) {
              RuntimeException r;
              try {
                  r = createException(e, templateReference);
              } catch (Exception ex) {
                  if (ex instanceof AmebaException) {
                      r = (RuntimeException) ex;
                  } else {
                      r = new TemplateException("create writeTo Exception error", e, -1);
                  }
              }
              throw r;
          }
      }
docs: {@inheritDoc}