本文整理了Java中groovy.lang.Writable.writeTo()
方法的一些代码示例,展示了Writable.writeTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Writable.writeTo()
方法的具体详情如下:
包路径:groovy.lang.Writable
类名称:Writable
方法名:writeTo
[英]writes this object to the given stream
[中]将此对象写入给定流
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* 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);
}
代码示例来源:origin: groovy/groovy-core
public Writer writeTo(final Writer out) throws IOException {
if (this.replacementNodeStack.empty()) {
for (Object child : this.children) {
if (child instanceof Writable) {
((Writable) child).writeTo(out);
} else {
out.write(child.toString());
}
}
return out;
} else {
return ((Writable) this.replacementNodeStack.peek()).writeTo(out);
}
}
代码示例来源:origin: apache/nifi
public void process(OutputStream out) throws IOException {
Writer w = new OutputStreamWriter(out, charset);
c.writeTo(w);
w.flush();
w.close();
}
});
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void renderMergedTemplateModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String url = getUrl();
Assert.state(url != null, "'url' not set");
Template template = getTemplate(url);
template.make(model).writeTo(new BufferedWriter(response.getWriter()));
}
代码示例来源:origin: apache/nifi
public void process(OutputStream out) throws IOException {
Writer w = new OutputStreamWriter(out, charset);
c.writeTo(w);
w.flush();
w.close();
}
});
代码示例来源:origin: groovy/groovy-core
private static String asString(Writable writable) {
if (writable instanceof GPathResult) {
return asString((GPathResult) writable); //GROOVY-4285
}
Writer sw = new StringWriter();
try {
writable.writeTo(sw);
} catch (IOException e) {
// ignore
}
return sw.toString();
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
protected void renderMergedTemplateModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String url = getUrl();
Assert.state(url != null, "'url' not set");
Template template = getTemplate(url);
template.make(model).writeTo(new BufferedWriter(response.getWriter()));
}
代码示例来源:origin: groovy/groovy-core
/**
* Renders an embedded template as a fragment. Fragments are cached in a template, meaning that
* if you use the same fragment in a template, it will only be compiled once, but once <b>per template
* instance</b>. This is less performant than using {@link #layout(java.util.Map, String)}.
*
* @param model model to be passed to the template
* @param templateText template body
* @return this template instance
* @throws IOException
* @throws ClassNotFoundException
*/
public Object fragment(Map model, String templateText) throws IOException, ClassNotFoundException {
Template template = cachedFragments.get(templateText);
if (template==null) {
template = engine.createTemplate(new StringReader(templateText));
cachedFragments.put(templateText, template);
}
template.make(model).writeTo(out);
return this;
}
代码示例来源:origin: org.codehaus.groovy/groovy
public String encode(final ClassNode node) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
DataOutputStream dos = new DataOutputStream(baos);
Writer wrt = new StringBuilderWriter();
String encoded = null;
try {
doEncode(node, dos);
EncodingGroovyMethods.encodeBase64(baos.toByteArray()).writeTo(wrt);
encoded = wrt.toString();
} catch (IOException e) {
throw new GroovyRuntimeException("Unable to serialize type information", e);
}
return encoded;
}
代码示例来源:origin: rest-assured/rest-assured
} else if (data instanceof Writable) {
StringWriter out = new StringWriter();
((Writable) data).writeTo(out);
out.flush();
data = out;
代码示例来源:origin: groovy/groovy-core
/**
* Includes another template inside this template.
* @param templatePath the path to the included resource.
* @throws IOException
* @throws ClassNotFoundException
*/
public void includeGroovy(String templatePath) throws IOException, ClassNotFoundException {
URL resource = engine.resolveTemplate(templatePath);
engine.createTypeCheckedModelTemplate(resource, modelTypes).make(model).writeTo(out);
}
代码示例来源:origin: org.codehaus.groovy/groovy
} else if (object instanceof Writable) {
Writable writable = (Writable) object;
writable.writeTo(out);
} else if (object instanceof InputStream || object instanceof Reader) {
代码示例来源:origin: org.codehaus.groovy/groovy
Writable writable = (Writable) object;
Writer stringWriter = new StringBuilderWriter();
writable.writeTo(stringWriter);
out.append(stringWriter.toString());
} else if (object instanceof InputStream || object instanceof Reader) {
代码示例来源:origin: groovy/groovy-core
template.make(binding.getVariables()).writeTo(out);
makeMillis = System.currentTimeMillis() - makeMillis;
代码示例来源:origin: groovy/groovy-core
/**
* Imports a template and renders it using the specified model, allowing fine grained composition of templates and
* layouting. This works similarily to a template include but allows a distinct model to be used. If the layout
* inherits from the parent model, a new model is created, with the values from the parent model, eventually
* overriden with those provided specifically for this layout.
*
* @param model model to be passed to the template
* @param templateName the name of the template to be used as a layout
* @param inheritModel a boolean indicating if we should inherit the parent model
* @return this template instance
* @throws IOException
* @throws ClassNotFoundException
*/
public Object layout(Map model, String templateName, boolean inheritModel) throws IOException, ClassNotFoundException {
Map submodel = inheritModel ? forkModel(model) : model;
URL resource = engine.resolveTemplate(templateName);
engine.createTypeCheckedModelTemplate(resource, modelTypes).make(submodel).writeTo(out);
return this;
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get(value = "/welcome", produces = MediaType.TEXT_PLAIN)
Writable render() { // <2>
return writer -> template.make( // <3>
CollectionUtils.mapOf(
"firstName", "Fred",
"lastName", "Flintstone"
)
).writeTo(writer);
}
代码示例来源:origin: org.codehaus.groovy/groovy-json
/**
* 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);
}
}
代码示例来源:origin: com.jayway.restassured/rest-assured
} else if (data instanceof Writable) {
StringWriter out = new StringWriter();
((Writable) data).writeTo(out);
out.flush();
data = out;
代码示例来源:origin: jbake-org/jbake
@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);
}
}
代码示例来源:origin: jbake-org/jbake
@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);
}
}
内容来源于网络,如有侵权,请联系作者删除!