Package groovy.lang

Examples of groovy.lang.Writable


     * @param chunked whether or not the Base64 encoded data should be MIME chunked
     * @return object which will write the Base64 encoding of the byte array
     * @since 1.5.7
     */
    public static Writable encodeBase64(final byte[] data, final boolean chunked) {
        return new Writable() {
            public Writer writeTo(final Writer writer) throws IOException {
                int charCount = 0;
                final int dLimit = (data.length / 3) * 3;

                for (int dIndex = 0; dIndex != dLimit; dIndex += 3) {
View Full Code Here


     * @param data byte array to be encoded
     * @return object which will write the hex encoding of the byte array
     * @see Integer#toHexString(int)
     */
    public static Writable encodeHex(final byte[] data) {
        return new Writable() {
            public Writer writeTo(Writer out) throws IOException {
                for (int i = 0; i < data.length; i++) {
                    // convert byte into unsigned hex string
                    String hexString = Integer.toHexString(data[i] & 0xFF);

View Full Code Here

    if (template == null) {
      return null;
    }
    try {
      final Template templateObject = templateEngine.createTemplate(template);
      final Writable writable = templateObject.make(variables);
      final StringWriter writer = new StringWriter();
      writable.writeTo(writer);
      writer.flush();
      if (log.isDebugEnabled() == true) {
        log.debug(writer.toString());
      }
      return writer.toString();
View Full Code Here

    @Override
    public void renderDocument(final Map<String, Object> model, final String templateName, final Writer writer) throws RenderingException {
        try {
            Template template = findTemplate(templateName);
            Writable writable = template.make(wrap(model));
            writable.writeTo(writer);
        } catch (Exception e) {
            throw new RenderingException(e);
        }
    }
View Full Code Here

    return template(new GStringTemplateEngine(), name, model);
  }

  public static String template(TemplateEngine engine, String name, Map<String, ?> model)
      throws IOException, CompilationFailedException, ClassNotFoundException {
    Writable writable = getTemplate(engine, name).make(model);
    StringWriter result = new StringWriter();
    writable.writeTo(result);
    return result.toString();
  }
View Full Code Here

    @Deprecated
    public void merge(Template template, BindingContext context) throws Exception {
        context.put("_ctx", context);
        context.setGroovyTemplateService(this);
        Writable writable = template.make(context);
        writable.writeTo(context.getWriter());
    }
View Full Code Here

   @Deprecated
   public void merge(Template template, BindingContext context) throws Exception
   {
      context.put("_ctx", context);
      context.setGroovyTemplateService(this);
      Writable writable = template.make(context);
      writable.writeTo(context.getWriter());
   }
View Full Code Here

    @Deprecated
    public void merge(Template template, BindingContext context) throws Exception {
        context.put("_ctx", context);
        context.setGroovyTemplateService(this);
        Writable writable = template.make(context);
        writable.writeTo(context.getWriter());
    }
View Full Code Here

    String contentType = template.getContentType();
    contentType = contentType == null ? context.get(MimeTypes.class).getContentType(template.getName()) : contentType;
    try {

      Template compiledTemplate = engine.createTemplateByPath(template.getName());
      Writable boundTemplate = compiledTemplate.make(template.getModel());
      context.getResponse().send(contentType, boundTemplate.toString());
    } catch (IOException e) {
      context.error(e);
    }
  }
View Full Code Here

        SimpleTemplateEngine engine = new SimpleTemplateEngine();

        Path templatePath = ClasspathHelper.getFilesystemPathFromClasspathPath("/betsy/common/analytics/html/HtmlAnalytics.template");

        try {
            Writable template = engine.createTemplate(templatePath.toFile()).make(getTemplateBinding());
            FileTasks.createFile(filename, template.toString());
        } catch (ClassNotFoundException | IOException e) {
            throw new RuntimeException("could not load template", e);
        }

    }
View Full Code Here

TOP

Related Classes of groovy.lang.Writable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.