Class MboxIterator
- java.lang.Object
-
- org.apache.james.mime4j.mboxiterator.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMboxIterator.Builderprivate classMboxIterator.MessageIterator
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBufferbyteBufferprivate java.nio.charset.CharsetDecoderDECODERprivate booleanendOfInputFlagFlag to signal end of input toCharsetDecoder.decode(java.nio.ByteBuffer).private intfindEndprivate intfindStartprivate booleanfromLineFoundprivate java.util.regex.MatcherfromLineMatcherprivate intmaxMessageSizeprivate java.nio.file.Pathmboxprivate java.nio.CharBuffermboxCharBufferprivate java.util.regex.PatternMESSAGE_START
-
Constructor Summary
Constructors Modifier Constructor Description privateMboxIterator(java.nio.file.Path mbox, java.nio.charset.Charset charset, java.lang.String regexpPattern, int regexpFlags, int MAX_MESSAGE_SIZE)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringbufferDetailsToString(java.nio.Buffer buffer)Utility method to log important details about buffers.voidclose()private voiddecodeNextCharBuffer()static MboxIterator.BuilderfromFile(java.io.File filePath)static MboxIterator.BuilderfromFile(java.lang.String file)static MboxIterator.BuilderfromFile(java.nio.file.Path filePath)protected voidinitMboxIterator()initialize the Mailbox iteratorjava.util.Iterator<CharBufferWrapper>iterator()private voidsaveFindPositions(java.util.regex.Matcher lineMatcher)private voidupdateEndOfInputFlag()
-
-
-
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 toCharsetDecoder.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.FileNotFoundExceptionjava.io.IOExceptionjava.io.CharConversionException
-
-
Method Detail
-
initMboxIterator
protected void initMboxIterator() throws java.io.IOExceptioninitialize the Mailbox iterator- Throws:
java.io.IOExceptionjava.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)
-
iterator
public java.util.Iterator<CharBufferWrapper> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<CharBufferWrapper>
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
fromFile
public static MboxIterator.Builder fromFile(java.nio.file.Path filePath)
-
fromFile
public static MboxIterator.Builder fromFile(java.io.File filePath)
-
fromFile
public static MboxIterator.Builder fromFile(java.lang.String file)
-
bufferDetailsToString
public static java.lang.String bufferDetailsToString(java.nio.Buffer buffer)
Utility method to log important details about buffers.- Parameters:
buffer-
-
-