private List < byte [ ] > getBytesFromFile ( Long [ ] offset , Integer [ ] length ) throws IOException { List < byte [ ] > vars = new ArrayList < byte [ ] > ( ) ; if ( cachedPage == null ) { for ( int i = 0 ; i < offset . length ; i ++ ) { byte [ ] temp = new byte [ length [ i ] ] ; long actuallySkipped = 0 ; while ( actuallySkipped < offset [ i ] - currentFilePosition ) { try { actuallySkipped += sasFileStream . skip ( offset [ i ] - currentFilePosition - actuallySkipped ) ; } catch ( IOException e ) { throw new IOException ( EMPTY_INPUT_STREAM ) ; } } try { sasFileStream . readFully ( temp , 0 , length [ i ] ) ; } catch ( EOFException e ) { eof = true ; } currentFilePosition = ( int ) ( long ) offset [ i ] + length [ i ] ; vars . add ( temp ) ; } } else { for ( int i = 0 ; i < offset . length ; i ++ ) { if ( cachedPage . length < offset [ i ] ) { throw new IOException ( EMPTY_INPUT_STREAM ) ; } vars . add ( Arrays . copyOfRange ( cachedPage , ( int ) ( long ) offset [ i ] , ( int ) ( long ) offset [ i ] + length [ i ] ) ) ; } } return vars ; }
The function to read the list of bytes arrays from the sas7bdat file . The array of offsets and the array of lengths serve as input data that define the location and number of bytes the function must read .