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

cn.luues.tool.template.AbstractTemplate Maven / Gradle / Ivy

There is a newer version: 2.0.1.RELEASE
Show newest version
package cn.luues.tool.template;

import cn.luues.tool.core.io.FileUtil;
import cn.luues.tool.core.io.IoUtil;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.StringWriter;
import java.util.Map;

/**
 * 抽象模板,提供将模板融合后写出到文件、返回字符串等方法
 * 
 * @author Mr-Wu
 *
 */
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy