* The array that backs this instance is the whole block of decoded messages.
*
* @return CharBuffer instance
*/
public CharBufferWrapper next() {
final CharBuffer message;
fromLineFound = fromLineMathcer.find();
if (fromLineFound) {
message = mboxCharBuffer.slice();
message.position(findEnd + 1);
saveFindPositions(fromLineMathcer);
message.limit(fromLineMathcer.start());
} else {
/* We didn't find other From_ lines this means either:
* - we reached end of mbox and no more messages
* - we reached end of CharBuffer and need to decode another batch.
*/
if (byteBuffer.hasRemaining()) {
// decode another batch, but remember to copy the remaining chars first
CharBuffer oldData = mboxCharBuffer.duplicate();
mboxCharBuffer.clear();
oldData.position(findStart);
while (oldData.hasRemaining()) {
mboxCharBuffer.put(oldData.get());
}
try {
decodeNextCharBuffer();
} catch (CharConversionException ex) {
throw new RuntimeException(ex);