public char charAt ( int index ) { if ( index < 0 || index >= this . length ( ) ) { throw new IndexOutOfBoundsException ( "index=" + index + " - should be between 0 and length()=" + this . length ( ) ) ; } // is it in the buffer if ( index < prefixBuffer . limit ( ) ) { return prefixBuffer . get ( index ) ; } // otherwise we gotta get it from disk via memory map long charFileIndex = ( long ) index - ( long ) prefixBuffer . limit ( ) ; long charFileLength = ( long ) this . length ( ) - ( long ) prefixBuffer . limit ( ) ; // in characters if ( charFileIndex * bytesPerChar < mapByteOffset ) { logger . log ( Level . WARNING , "left-fault; probably don't want to use CharSequence that far backward" ) ; } if ( charFileIndex * bytesPerChar < mapByteOffset || charFileIndex - ( mapByteOffset / bytesPerChar ) >= mappedBuffer . limit ( ) ) { // fault /* * mapByteOffset is bounded by 0 and file size +/- size of the map, * and starts as close to <code>fileIndex - * MAP_TARGET_LEFT_PADDING_BYTES</code> as it can while also not * being smaller than it needs to be. */ mapByteOffset = Math . min ( charFileIndex * bytesPerChar - MAP_TARGET_LEFT_PADDING_BYTES , charFileLength * bytesPerChar - MAP_MAX_BYTES ) ; mapByteOffset = Math . max ( 0 , mapByteOffset ) ; updateMemoryMappedBuffer ( ) ; } return mappedBuffer . get ( ( int ) ( charFileIndex - ( mapByteOffset / bytesPerChar ) ) ) ; }
Get character at passed absolute position .