nl_tokens: Copy some or all chars from a large ( over 2GB ) <code > InputStream< / code > to an <code > OutputStream< / code > optionally skipping input chars . <p / > This method uses the provided buffer so there is no need to use a <code > BufferedReader< / code > . <p / >
pl_tokens: public static long copyLarge ( Reader input , Writer output , final long inputOffset , final long length , char [ ] buffer ) throws IOException { if ( inputOffset > 0 ) { skipFully ( input , inputOffset ) ; } if ( length == 0 ) { return 0 ; } int bytesToRead = buffer . length ; if ( length > 0 && length < buffer . length ) { bytesToRead = ( int ) length ; } int read ; long totalRead = 0 ; while ( bytesToRead > 0 && EOF != ( read = input . read ( buffer , 0 , bytesToRead ) ) ) { output . write ( buffer , 0 , read ) ; totalRead += read ; if ( length > 0 ) { // only adjust length if not reading to the end // Note the cast must work because buffer.length is an integer bytesToRead = ( int ) Math . <mask> ( length - totalRead , buffer . length ) ; } } return totalRead ; }