Class MIMEParser
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) classprivate static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]private final intprivate final byte[]private booleanprivate byte[]private final intprivate final MIMEConfigprivate booleanprivate booleanprivate final int[]private static final Stringprivate final InputStreamprivate intprivate static final Loggerprivate static final intprivate booleanHave we parsed the data from our InputStream yet?private MIMEParser.STATE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ByteBufferadjustBuf(int chunkSize, int remaining) Returns a chunk from the original buffer.private voidBoyer-Moore search method.private voidcreateBuf(int min) private voidprivate voidfillBuf()Fills the remaining buf to the full capacityprivate static byte[]iterator()Returns iterator for the parsing events.private intmatch(byte[] mybuf, int off, int len) Finds the boundary in the given buffer using Boyer-Moore algo.private ByteBufferreadBody()Reads and saves the part of the current attachment part's content.private InternetHeadersCollects the headers for the current part by parsing mesage stream.private voidSkips the preamble to find the first attachment partMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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
-
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()
-