cn.hutool.extra.template.AbstractTemplate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.extra.template;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.StringWriter;
import java.util.Map;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
/**
* 抽象模板,提供将模板融合后写出到文件、返回字符串等方法
*
* @author looly
*
*/
public abstract class AbstractTemplate implements Template{
@Override
public void render(Map bindingMap, File file) {
BufferedOutputStream out = null;
try {
out = FileUtil.getOutputStream(file);
this.render(bindingMap, out);
} finally {
IoUtil.close(out);
}
}
@Override
public String render(Map bindingMap) {
final StringWriter writer = new StringWriter();
render(bindingMap, writer);
return writer.toString();
}
}