01: package net.sf.mockcreator.utils;
02:
03: import net.sf.mockcreator.exceptions.MockException;
04:
05: import java.io.InputStream;
06: import java.text.MessageFormat;
07:
08: public class TemplateUtils {
09:
10: public static String format(String name, Object[] params) {
11: return MessageFormat.format(getTemplate(name), params);
12: }
13:
14: public static String getTemplate(String name) {
15: InputStream is = null;
16: try {
17: is = Thread.currentThread().getContextClassLoader()
18: .getResourceAsStream(name);
19: StringBuffer sb = new StringBuffer();
20: while (is.available() > 0) {
21: sb.append((char) is.read());
22: }
23: is.close();
24: return sb.toString();
25: } catch (Exception ex) {
26: throw new MockException("failed to get template " + name,
27: ex);
28: }
29: }
30:
31: }
|