本文整理汇总了Java中groovy.lang.Writable.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java Writable.writeTo方法的具体用法?Java Writable.writeTo怎么用?Java Writable.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类groovy.lang.Writable
的用法示例。
在下文中一共展示了Writable.writeTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderDocument
import groovy.lang.Writable; //导入方法依赖的package包/类
@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);
}
}
示例2: renderDocument
import groovy.lang.Writable; //导入方法依赖的package包/类
@Override
public void renderDocument(final Map<String, Object> model, final String templateName, final Writer writer) throws RenderingException {
try {
Template template = templateEngine.createTemplateByPath(templateName);
Map<String, Object> wrappedModel = wrap(model);
Writable writable = template.make(wrappedModel);
writable.writeTo(writer);
} catch (Exception e) {
throw new RenderingException(e);
}
}
示例3: template
import groovy.lang.Writable; //导入方法依赖的package包/类
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();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:GroovyTemplate.java
示例4: call
import groovy.lang.Writable; //导入方法依赖的package包/类
/**
* Writes the given Writable as the value of the given attribute name
*
* @param name The attribute name
* @param json The writable value
* @throws IOException
*/
public void call(String name, Writable json) throws IOException {
writeName(name);
verifyValue();
if(json instanceof GString) {
writer.write(generator.toJson(json.toString()));
}
else {
json.writeTo(writer);
}
}
示例5: asString
import groovy.lang.Writable; //导入方法依赖的package包/类
private static String asString(Writable writable) {
if (writable instanceof GPathResult) {
return asString((GPathResult) writable); //GROOVY-4285
}
Writer sw = new StringBuilderWriter();
try {
writable.writeTo(sw);
} catch (IOException e) {
// ignore
}
return sw.toString();
}
示例6: write
import groovy.lang.Writable; //导入方法依赖的package包/类
/**
* Writes an object to a Writer using Groovy's default representation for the object.
*/
public static void write(Writer out, Object object) throws IOException {
if (object instanceof String) {
out.write((String) object);
} else if (object instanceof Object[]) {
out.write(toArrayString((Object[]) object));
} else if (object instanceof Map) {
out.write(toMapString((Map) object));
} else if (object instanceof Collection) {
out.write(toListString((Collection) object));
} else if (object instanceof Writable) {
Writable writable = (Writable) object;
writable.writeTo(out);
} else if (object instanceof InputStream || object instanceof Reader) {
// Copy stream to stream
Reader reader;
if (object instanceof InputStream) {
reader = new InputStreamReader((InputStream) object);
} else {
reader = (Reader) object;
}
char[] chars = new char[8192];
int i;
while ((i = reader.read(chars)) != -1) {
out.write(chars, 0, i);
}
reader.close();
} else {
out.write(toString(object));
}
}
示例7: append
import groovy.lang.Writable; //导入方法依赖的package包/类
/**
* Appends an object to an Appendable using Groovy's default representation for the object.
*/
public static void append(Appendable out, Object object) throws IOException {
if (object instanceof String) {
out.append((String) object);
} else if (object instanceof Object[]) {
out.append(toArrayString((Object[]) object));
} else if (object instanceof Map) {
out.append(toMapString((Map) object));
} else if (object instanceof Collection) {
out.append(toListString((Collection) object));
} else if (object instanceof Writable) {
Writable writable = (Writable) object;
Writer stringWriter = new StringBuilderWriter();
writable.writeTo(stringWriter);
out.append(stringWriter.toString());
} else if (object instanceof InputStream || object instanceof Reader) {
// Copy stream to stream
Reader reader;
if (object instanceof InputStream) {
reader = new InputStreamReader((InputStream) object);
} else {
reader = (Reader) object;
}
char[] chars = new char[8192];
int i;
while ((i = reader.read(chars)) != -1) {
for (int j = 0; j < i; j++) {
out.append(chars[j]);
}
}
reader.close();
} else {
out.append(toString(object));
}
}
示例8: evaluate
import groovy.lang.Writable; //导入方法依赖的package包/类
@Override
public void evaluate(Writer output, Map<String, Object> binding) throws GrafikonException {
if (templateGString == null) {
initialize();
}
Writable result = templateGString.make(binding);
try {
result.writeTo(output);
output.flush();
} catch (IOException e) {
throw new GrafikonException("Error writing output.", e);
}
}
示例9: process
import groovy.lang.Writable; //导入方法依赖的package包/类
private static ArrayList<String> process(File template_file, HashMap<String, Object> all_mail_vars) throws IOException, CompilationFailedException, ClassNotFoundException {
Template template = template_engine.createTemplate(template_file);
Writable writable = template.make(all_mail_vars);
TemplateWriter tw = new TemplateWriter();
writable.writeTo(tw);
return tw.getContent();
}
示例10: main
import groovy.lang.Writable; //导入方法依赖的package包/类
public static void main(String... args) throws ClassNotFoundException, IOException {
Method[] methodDeclarations = Class.forName("com.github.timofeevda.gwt.rxjs.interop.observable.Observable")
.getDeclaredMethods();
Set<String> importsSet = generateImportsSet(methodDeclarations);
List<GeneratedMethodDefinition> generatedMethodDefinitions = generateMethodsDefintions(methodDeclarations);
SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
InputStream templateStream = MethodDefinitionsTestsGenerator.class.getResourceAsStream("/definitions.template");
Map<String, Object> templateBindings = new HashMap<>();
templateBindings.put("methods", generatedMethodDefinitions);
templateBindings.put("importsSet", importsSet);
File destinationFile = new File(args[0]);
destinationFile.mkdirs();
File testDefinitonsFile = new File(args[0] + File.separator + "MethodsDefinitionsTest.java");
testDefinitonsFile.createNewFile();
Writable writable = templateEngine.createTemplate(new BufferedReader(new InputStreamReader(templateStream))).make(templateBindings);
writable.writeTo(new PrintWriter(new FileOutputStream(testDefinitonsFile)));
}
示例11: doGenerate
import groovy.lang.Writable; //导入方法依赖的package包/类
@Override
public void doGenerate(final Map<String, Object> map, final Path output, final Path templateFile) {
Object _get = map.get("u");
final GeneratorUtils utils = ((GeneratorUtils) _get);
final IClass iClass = utils.getIclass();
try {
final Template template = this.engine.createTemplate(templateFile.toFile());
final Writable generatedCode = template.make(map);
File _file = output.toFile();
FileWriter _fileWriter = new FileWriter(_file);
final Function1<FileWriter, Writer> _function = (FileWriter it) -> {
try {
return generatedCode.writeTo(it);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
Using.<FileWriter, Writer>using(_fileWriter, _function);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception)_t;
GenerationException.getInstance().addException(e);
boolean _matched = false;
if (Objects.equal(e, MissingPropertyException.class)) {
_matched=true;
JFrame _frame = utils.getFrame();
String _message = e.getMessage();
String _plus = ("Cannot found property :" + _message);
String _plus_1 = (_plus + ". model : ");
String _name = iClass.getName();
String _plus_2 = (_plus_1 + _name);
JOptionPane.showMessageDialog(_frame, _plus_2);
}
if (!_matched) {
JFrame _frame_1 = utils.getFrame();
String _message_1 = e.getMessage();
String _plus_3 = (_message_1 + ".\n in model : ");
String _name_1 = iClass.getName();
String _plus_4 = (_plus_3 + _name_1);
JOptionPane.showMessageDialog(_frame_1, _plus_4);
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
示例12: write
import groovy.lang.Writable; //导入方法依赖的package包/类
/**
* A helper method so that dynamic dispatch of the writer.write(object) method
* will always use the more efficient Writable.writeTo(writer) mechanism if the
* object implements the Writable interface.
*
* @param self a Writer
* @param writable an object implementing the Writable interface
* @throws IOException if an I/O error occurs.
* @since 1.0
*/
public static void write(Writer self, Writable writable) throws IOException {
writable.writeTo(self);
}