title: How to merge java.io.Reader's or wrap Reader's content?
body: <p>I am wrapping Freemarker template loader in Spring MVC as described <a href="https://stackoverflow.com/a/1678940/1307586">here</a> to have default escaping in html pages.</p>
  
  <p>So, I need to wrap content from java.io.Reader with my strings, not reading it, not converting it to string and not implementing myself. Is there class similar to <a href="http://metadata-net.svn.sourceforge.net/viewvc/metadata-net/shared/trunk/util/src/main/java/au/edu/uq/itee/maenad/util/WrappingReader.java?revision=1132&amp;view=markup" rel="nofollow noreferrer">WrappingReader</a> or com.google.common.io.MultiReader (which is not public) in popular common libraries?</p>
  
  <p>My implementation:</p>
  
  <pre><code>import com.google.common.io.CharStreams;
  import com.google.common.io.InputSupplier;
  
  ...
  
  private final TemplateLoader delegate;
  
  @Autowired
  public HtmlEscapingTemplateLoader(ResourceLoader resourceLoader)
  {
      delegate = new SpringTemplateLoader(resourceLoader, "/WEB-INF/templates/");
  }
  
  @Override
  public Reader getReader(Object templateSource, String encoding) throws IOException
  {
      // collecting readers
      Reader prologue = new StringReader("&lt;#escape x as x?html&gt;");
      Reader originalReader = delegate.getReader(templateSource, encoding);
      Reader epilogue = new StringReader("&lt;/#escape&gt;");
  
      // concatenating readers
      return merge(prologue, originalReader, epilogue);
  }
  
  
  protected Reader merge(Reader prologue, Reader originalReader, Reader epilogue) throws IOException
  {
      return CharStreams.join(
              Arrays.asList(new ReaderSupplier(prologue), new ReaderSupplier(originalReader), new ReaderSupplier(
                      epilogue))).getInput();
  }
  
  private static class ReaderSupplier
          implements InputSupplier&lt;Reader&gt;
  {
  
      private final Reader reader;
  
      public ReaderSupplier(Reader reader)
      {
          this.reader = reader;
      }
  
      @Override
      public Reader getInput() throws IOException
      {
          return reader;
      }
  
  }
  </code></pre>
  
  <p>CharStreams i use is marked as @com.google.common.annotations.Beta. So, could it be rewritten in more solid way without usage of CharStreams?</p>