Originally posted by David Harkness:
Not if you set the ByteBuffer's position and limit of the buffer before decoding it. Loop over the mapped buffer, setting up a good block size using position and limit. Decocding will now just decode the bytes in the range you specify.
Use CharsetDecoder.decode(ByteBuffer, CharBuffer) or one of the other similar methods so you can reuse the same CharBuffer. Since decoding advances the position, it should leave you at the next correct spot, dealing with multi-byte character encodings for you; just set limit to be position + BLOCK_SIZE and keep going.
If you want ultimate speed, cannot count on ASCII files, and don't want to write your own specialized decoder, this is the way to go.