static public long copyRafB ( ucar . unidata . io . RandomAccessFile raf , long offset , long length , OutputStream out , byte [ ] buffer ) throws IOException { int bufferSize = buffer . length ; long want = length ; raf . seek ( offset ) ; while ( want > 0 ) { int len = ( int ) Math . min ( want , bufferSize ) ; int bytesRead = raf . read ( buffer , 0 , len ) ; if ( bytesRead <= 0 ) break ; out . write ( buffer , 0 , bytesRead ) ; want -= bytesRead ; } out . flush ( ) ; return length - want ; }
Copy part of a RandomAccessFile to output stream specify internal buffer size