Knowledge Walls
John Peter
Pune, Maharashtra, India
How to use Input stream or BLOB binary stream as velocity template file with Example
In this example how to use blob data instead of vm file from FilePath.

RuntimeServices Class provides the interface to the Template class and template parse the blob information via StringBuffer castring. DB based blob data can use as template instead of using .vm files.
Blob blob = new SerialBlob("Username is $username".getBytes());

RuntimeServices rs = RuntimeSingleton.getRuntimeServices();            
StringReader sr = new StringReader(IOUtils.toString(blob.getBinaryStream()));
SimpleNode sn = rs.parse(sr, "User Information");

Template t = new Template();

VelocityContext vc = new VelocityContext();
vc.put("username", "John");

StringWriter sw = new StringWriter();
t.merge(vc, sw);
BLOB Binary stream data 
Username is $username
Username is John
Best Lessons of "Java Apache Velocity Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details