private long copyLarge ( final InputStream input , final OutputStream output , final int bufferSize ) throws IOException { final byte [ ] buffer = new byte [ bufferSize ] ; long count = 0 ; int n = 0 ; while ( - 1 != ( n = input . read ( buffer ) ) ) { output . write ( buffer , 0 , n ) ; count += n ; } log . debug ( "Copied bytes: {}" , count ) ; return count ; }
This is copied from Jakarta Commons IOUtils . For some reason our series of atypical socket stream chains break without a flush after each of these calls so it s added in .