All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.it.freemarker.Base64Directive Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package io.quarkiverse.it.freemarker;

import static java.nio.charset.StandardCharsets.*;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Base64;
import java.util.Map;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

public class Base64Directive implements TemplateDirectiveModel {
    @Override
    public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody body)
            throws TemplateException, IOException {
        StringWriter sw = new StringWriter();
        body.render(sw);
        byte[] bytes = Base64.getEncoder().encode(sw.toString().getBytes(UTF_8));
        environment.getOut().write(new String(bytes, UTF_8));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy