Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-714

Change ResourceLoader API to return Reader instances instead of InputStreams

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • None
    • None
    • Engine
    • 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

          Activity

            People

              Unassigned Unassigned
              wyla Jarkko Viinamäki
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: