public static OutputStream createArrayOutputStream ( final OutputStream [ ] outputStreams ) { return new OutputStream ( ) { @ Override public void close ( ) throws IOException { for ( OutputStream o : outputStreams ) { o . close ( ) ; } super . close ( ) ; } @ Override public void flush ( ) throws IOException { for ( OutputStream o : outputStreams ) { o . flush ( ) ; } super . flush ( ) ; } @ Override public void write ( int oneByte ) throws IOException { for ( OutputStream o : outputStreams ) { o . write ( oneByte ) ; } } @ Override public void write ( byte [ ] buffer ) throws IOException { for ( OutputStream o : outputStreams ) { o . write ( buffer ) ; } } @ Override public void write ( byte [ ] buffer , int offset , int count ) throws IOException { for ( OutputStream o : outputStreams ) { o . write ( buffer , offset , count ) ; } } } ; }
Helper method that wraps given arrays inside of a single outputstream .