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 class
MboxIterator.Builder
private class
MboxIterator.MessageIterator
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer
byteBuffer
private java.nio.charset.CharsetDecoder
DECODER
private boolean
endOfInputFlag
Flag to signal end of input toCharsetDecoder.decode(java.nio.ByteBuffer)
.private int
findEnd
private int
findStart
private boolean
fromLineFound
private java.util.regex.Matcher
fromLineMatcher
private int
maxMessageSize
private java.nio.file.Path
mbox
private java.nio.CharBuffer
mboxCharBuffer
private java.util.regex.Pattern
MESSAGE_START
-
Constructor Summary
Constructors Modifier Constructor Description private
MboxIterator(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.String
bufferDetailsToString(java.nio.Buffer buffer)
Utility method to log important details about buffers.void
close()
private void
decodeNextCharBuffer()
static MboxIterator.Builder
fromFile(java.io.File filePath)
static MboxIterator.Builder
fromFile(java.lang.String file)
static MboxIterator.Builder
fromFile(java.nio.file.Path filePath)
protected void
initMboxIterator()
initialize the Mailbox iteratorjava.util.Iterator<CharBufferWrapper>
iterator()
private void
saveFindPositions(java.util.regex.Matcher lineMatcher)
private void
updateEndOfInputFlag()
-
-
-
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.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)
-
iterator
public java.util.Iterator<CharBufferWrapper> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<CharBufferWrapper>
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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
-
-
-