Class MboxIterator

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<CharBufferWrapper>

    public class MboxIterator
    extends java.lang.Object
    implements java.lang.Iterable<CharBufferWrapper>, java.io.Closeable

    Class that provides an iterator over email messages inside an mbox file. An mbox file is a sequence of email messages separated by From_ lines.

    Description ot the file format:

    • http://tools.ietf.org/html/rfc4155
    • http://qmail.org/man/man5/mbox.html
    • Field Detail

      • mboxCharBuffer

        private final java.nio.CharBuffer mboxCharBuffer
      • fromLineMatcher

        private java.util.regex.Matcher fromLineMatcher
      • fromLineFound

        private boolean fromLineFound
      • byteBuffer

        private final java.nio.ByteBuffer byteBuffer
      • DECODER

        private final java.nio.charset.CharsetDecoder DECODER
      • endOfInputFlag

        private boolean endOfInputFlag
        Flag to signal end of input to CharsetDecoder.decode(java.nio.ByteBuffer) .
      • maxMessageSize

        private final int maxMessageSize
      • MESSAGE_START

        private final java.util.regex.Pattern MESSAGE_START
      • findStart

        private int findStart
      • findEnd

        private int findEnd
      • mbox

        private final java.nio.file.Path mbox
    • Constructor Detail

      • MboxIterator

        private MboxIterator​(java.nio.file.Path mbox,
                             java.nio.charset.Charset charset,
                             java.lang.String regexpPattern,
                             int regexpFlags,
                             int MAX_MESSAGE_SIZE)
                      throws java.io.FileNotFoundException,
                             java.io.IOException,
                             java.io.CharConversionException
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
        java.io.CharConversionException
    • Method Detail

      • initMboxIterator

        protected void initMboxIterator()
                                 throws java.io.IOException
        initialize the Mailbox iterator
        Throws:
        java.io.IOException
        java.io.CharConversionException
      • decodeNextCharBuffer

        private void decodeNextCharBuffer()
                                   throws java.io.CharConversionException
        Throws:
        java.io.CharConversionException
      • updateEndOfInputFlag

        private void updateEndOfInputFlag()
      • saveFindPositions

        private void saveFindPositions​(java.util.regex.Matcher lineMatcher)
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • bufferDetailsToString

        public static java.lang.String bufferDetailsToString​(java.nio.Buffer buffer)
        Utility method to log important details about buffers.
        Parameters:
        buffer -