java.lang.Object
org.jvnet.mimepull.MIMEParser
Pull parser for the MIME messages. Applications can use pull API to continue
the parsing MIME messages lazily.
for e.g.:
MIMEParser parser = ...
Iterator<MIMEEvent> it = parser.iterator();
while(it.hasNext()) {
MIMEEvent event = it.next();
...
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
(package private) class
private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]
private final int
private final byte[]
private boolean
private byte[]
private final int
private final MIMEConfig
private boolean
private boolean
private final int[]
private static final String
private final InputStream
private int
private static final Logger
private static final int
private boolean
Have we parsed the data from our InputStream yet?private MIMEParser.STATE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ByteBuffer
adjustBuf
(int chunkSize, int remaining) Returns a chunk from the original buffer.private void
Boyer-Moore search method.private void
createBuf
(int min) private void
private void
fillBuf()
Fills the remaining buf to the full capacityprivate static byte[]
iterator()
Returns iterator for the parsing events.private int
match
(byte[] mybuf, int off, int len) Finds the boundary in the given buffer using Boyer-Moore algo.private ByteBuffer
readBody()
Reads and saves the part of the current attachment part's content.private InternetHeaders
Collects the headers for the current part by parsing mesage stream.private void
Skips the preamble to find the first attachment partMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
LOGGER
-
HEADER_ENCODING
- See Also:
-
NO_LWSP
private static final int NO_LWSP- See Also:
-
state
-
in
-
bndbytes
private final byte[] bndbytes -
bl
private final int bl -
config
-
bcs
private final int[] bcs -
gss
private final int[] gss -
parsed
private boolean parsedHave we parsed the data from our InputStream yet? -
done
private boolean done -
eof
private boolean eof -
capacity
private final int capacity -
buf
private byte[] buf -
len
private int len -
bol
private boolean bol
-
-
Constructor Details
-
MIMEParser
MIMEParser(InputStream in, String boundary, MIMEConfig config)
-
-
Method Details
-
iterator
Returns iterator for the parsing events. Use the iterator to advance the parsing. -
readHeaders
Collects the headers for the current part by parsing mesage stream.- Returns:
- headers for the current part
-
readBody
Reads and saves the part of the current attachment part's content. At the end of this method, buf should have the remaining data at index 0.- Returns:
- a chunk of the part's content
-
adjustBuf
Returns a chunk from the original buffer. A new buffer is created with the remaining bytes.- Parameters:
chunkSize
- create a chunk with these many bytesremaining
- bytes from the end of the buffer that need to be copied to the beginning of the new buffer- Returns:
- chunk
-
createBuf
private void createBuf(int min) -
skipPreamble
private void skipPreamble()Skips the preamble to find the first attachment part -
getBytes
-
compileBoundaryPattern
private void compileBoundaryPattern()Boyer-Moore search method. Copied from java.util.regex.Pattern.java Pre calculates arrays needed to generate the bad character shift and the good suffix shift. Only the last seven bits are used to see if chars match; This keeps the tables small and covers the heavily used ASCII range, but occasionally results in an aliased match for the bad character shift. -
match
private int match(byte[] mybuf, int off, int len) Finds the boundary in the given buffer using Boyer-Moore algo. Copied from java.util.regex.Pattern.java- Parameters:
mybuf
- boundary to be searched in this mybufoff
- start index in mybuflen
- number of bytes in mybuf- Returns:
- -1 if there is no match or index where the match starts
-
fillBuf
private void fillBuf()Fills the remaining buf to the full capacity -
doubleBuf
private void doubleBuf()
-