@Override
 public void onClose(CachedOutputStream wrapper) {
   InputStream transformedStream = null;
   try {
     transformedStream = XSLTUtils.transform(xsltTemplate, wrapper.getInputStream());
     IOUtils.copyAndCloseInput(transformedStream, origStream);
   } catch (IOException e) {
     throw new Fault("STREAM_COPY", LOG, e, e.getMessage());
   } finally {
     try {
       origStream.close();
     } catch (IOException e) {
       LOG.warning("Cannot close stream after transformation: " + e.getMessage());
     }
   }
 }
 @Override
 protected void doClose() {
   Reader transformedReader = null;
   try {
     transformedReader = XSLTUtils.transform(xsltTemplate, getReader());
     IOUtils.copyAndCloseInput(transformedReader, origWriter, IOUtils.DEFAULT_BUFFER_SIZE);
   } catch (IOException e) {
     throw new Fault("READER_COPY", LOG, e, e.getMessage());
   } finally {
     try {
       origWriter.close();
     } catch (IOException e) {
       LOG.warning("Cannot close stream after transformation: " + e.getMessage());
     }
   }
 }
 @Override
 public void close() {
   Reader transformedReader = null;
   try {
     super.flush();
     transformedReader = XSLTUtils.transform(xsltTemplate, cachedWriter.getReader());
     StaxUtils.copy(new StreamSource(transformedReader), origXWriter);
   } catch (XMLStreamException e) {
     throw new Fault("STAX_COPY", LOG, e, e.getMessage());
   } catch (IOException e) {
     throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
   } finally {
     try {
       if (transformedReader != null) {
         transformedReader.close();
       }
       cachedWriter.close();
       StaxUtils.close(origXWriter);
       super.close();
     } catch (Exception e) {
       LOG.warning("Cannot close stream after transformation: " + e.getMessage());
     }
   }
 }