Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
None
-
None
-
None
Description
Abstract class org.apache.velocity.runtime.resource.loader.ResourceLoader contains method
public abstract InputStream getResourceStream( String source )
throws ResourceNotFoundException;
However, in org.apache.velocity.Template.process() there is code (abbreviated):
try
{ is = resourceLoader.getResourceStream(name); }catch( ResourceNotFoundException rnfe )
{ errorCondition = rnfe; throw rnfe; } if (is != null)
{
try
{
BufferedReader br = new BufferedReader( new InputStreamReader( is, encoding ) );
data = rsvc.parse( br, name);
...
This seems a bit silly. ResourceLoaders should obviously return Reader instances since those would allow loaders to take content encoding into account. Currently this is problematic especially with DataSourceResourceLoader (VELOCITY-599). If we want to support UTF-8 in DataSourceResourceLoader, with current API we would first have to use ResultSet.getCharacterStream to get a Reader, then read all stuff into a String, then convert it into UTF-8 encoding with getBytes call but then in the Template the whole stuff is then converted back to a Reader. That's a lot of waste.
I think it would make more sense if the ResourceLoader API contained a method:
public abstract Reader getResource( String source )
throws ResourceNotFoundException;
Attachments
Issue Links
- is related to
-
VELOCITY-599 DataSourceResourceLoader doesn't support UTF8
- Closed
-
VELOCITY-451 Do some investigation into UTF-16 and InputStream / Reader interfaces
- Resolved