public static byte [ ] loadBytes ( long offset , int length , RandomAccessFile raf ) throws IOException { if ( length < 0 ) { length = 0 ; logger . error ( "Negative length: " + length ) ; } if ( offset < 0 ) { offset = 0 ; logger . error ( "Negative offset: " + offset ) ; } // stay within file bounds offset = Math . min ( offset , raf . length ( ) ) ; long endOffset = Math . min ( offset + length , raf . length ( ) ) ; length = ( int ) ( endOffset - offset ) ; raf . seek ( offset ) ; byte [ ] bytes = new byte [ length ] ; raf . readFully ( bytes ) ; return bytes ; }
Loads the bytes at the offset into a byte array with the given length using the raf .