Class OutputStreamCopier

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public class OutputStreamCopier
    extends OutputStream
    Copy original output stream to byte[] object. Usage:
     // get the stream
     OutputStream originalStream = context.getOutputStream();
     // create this stream copier object
     OutputStreamCopier osc = new OutputStreamCopier(originalStream);
     // set back this created stream
     context.setOutputStream(osc);
     // call stream consumer, example:
     try {
         context.proceed();
     } finally {
         context.setOutputStream(originalStream);
     }
     // get the stream data copy and use to anything
     byte[] byteCopy = osc.getCopy();
     
    Since:
    1.0.0
    Author:
    imre.scheffer
    • Constructor Detail

      • OutputStreamCopier

        public OutputStreamCopier​(OutputStream outputStream)
        Constructor
        Parameters:
        outputStream - original outputStream what we want to copy
    • Method Detail

      • getCopy

        public byte[] getCopy()
        Copy of used output stream data.
        Returns:
        byte array copy