public static void copy ( Reader in , Writer out , long byteCount ) throws IOException { char buffer [ ] = new char [ bufferSize ] ; int len = bufferSize ; if ( byteCount >= 0 ) { while ( byteCount > 0 ) { if ( byteCount < bufferSize ) len = in . read ( buffer , 0 , ( int ) byteCount ) ; else len = in . read ( buffer , 0 , bufferSize ) ; if ( len == - 1 ) break ; byteCount -= len ; out . write ( buffer , 0 , len ) ; } } else { while ( true ) { len = in . read ( buffer , 0 , bufferSize ) ; if ( len == - 1 ) break ; out . write ( buffer , 0 , len ) ; } } }
Copy Reader to Writer for byteCount bytes or until EOF or exception .