final ByteBuffer[] map(String resourceDescription,FileChannel fc,long offset,long length) throws IOException {
  if ((length >>> chunkSizePower) >= Integer.MAX_VALUE)   throw new IllegalArgumentException("RandomAccessFile too big for chunk size: " + resourceDescription);
  final long chunkSize=1L << chunkSizePower;
  final int nrBuffers=(int)(length >>> chunkSizePower) + 1;
  ByteBuffer buffers[]=new ByteBuffer[nrBuffers];
  long bufferStart=0L;
  for (int bufNr=0; bufNr < nrBuffers; bufNr++) {
    int bufSize=(int)((length > (bufferStart + chunkSize)) ? chunkSize : (length - bufferStart));
    MappedByteBuffer buffer;
    try {
      buffer=fc.map(MapMode.READ_ONLY,offset + bufferStart,bufSize);
    }
 catch (    IOException ioe) {
      throw convertMapFailedIOException(ioe,resourceDescription,bufSize);
    }
    if (preload) {
      buffer.load();
    }
    buffers[bufNr]=buffer;
    bufferStart+=bufSize;
  }
  return buffers;
}

final ByteBuffer [ ] map ( String resourceDescription , FileChannel fc , long offset , long length ) throws IOException { if ( ( length > > > chunkSizePower ) >= Integer . MAX_VALUE ) throw new IllegalArgumentException ( "RandomAccessFile too big for chunk size: " + resourceDescription ) ; final long chunkSize = 1L << chunkSizePower ; final int nrBuffers = ( int ) ( length > > > chunkSizePower ) + 1 ; ByteBuffer buffers [ ] = new ByteBuffer [ nrBuffers ] ; long bufferStart = 0L ; for ( int bufNr = 0 ; bufNr < nrBuffers ; bufNr ++ ) { int bufSize = ( int ) ( ( length > ( bufferStart + chunkSize ) ) ? chunkSize : ( length - bufferStart ) ) ; MappedByteBuffer buffer ; try { buffer = fc . map ( MapMode . READ_ONLY , offset + bufferStart , bufSize ) ; } catch ( IOException ioe ) { throw convertMapFailedIOException ( ioe , resourceDescription , bufSize ) ; } if ( preload ) { buffer . load ( ) ; } buffers [ bufNr ] = buffer ; bufferStart += bufSize ; } return buffers ; }
maps a file into a set of buffers
