Package org.jvnet.mimepull
Class MIMEParser
- java.lang.Object
-
- org.jvnet.mimepull.MIMEParser
-
- All Implemented Interfaces:
java.lang.Iterable<MIMEEvent>
class MIMEParser extends java.lang.Object implements java.lang.Iterable<MIMEEvent>
Pull parser for the MIME messages. Applications can use pull API to continue the parsing MIME messages lazily.for e.g.:
MIMEParser parser = ... Iterator
it = parser.iterator(); while(it.hasNext()) { MIMEEvent event = it.next(); ... }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
MIMEParser.LineInputStream
(package private) class
MIMEParser.MIMEEventIterator
private static class
MIMEParser.STATE
-
Field Summary
Fields Modifier and Type Field Description private int[]
bcs
private int
bl
private byte[]
bndbytes
private boolean
bol
private byte[]
buf
private int
capacity
private MIMEConfig
config
private boolean
done
private boolean
eof
private int[]
gss
private static java.lang.String
HEADER_ENCODING
private java.io.InputStream
in
private int
len
private static java.util.logging.Logger
LOGGER
private static int
NO_LWSP
private boolean
parsed
Have we parsed the data from our InputStream yet?private MIMEParser.STATE
state
-
Constructor Summary
Constructors Constructor Description MIMEParser(java.io.InputStream in, java.lang.String boundary, MIMEConfig config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.nio.ByteBuffer
adjustBuf(int chunkSize, int remaining)
Returns a chunk from the original buffer.private void
compileBoundaryPattern()
Boyer-Moore search method.private void
createBuf(int min)
private void
doubleBuf()
private void
fillBuf()
Fills the remaining buf to the full capacityprivate static byte[]
getBytes(java.lang.String s)
java.util.Iterator<MIMEEvent>
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 java.nio.ByteBuffer
readBody()
Reads and saves the part of the current attachment part's content.private InternetHeaders
readHeaders()
Collects the headers for the current part by parsing mesage stream.private void
skipPreamble()
Skips the preamble to find the first attachment part
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
HEADER_ENCODING
private static final java.lang.String HEADER_ENCODING
- See Also:
- Constant Field Values
-
NO_LWSP
private static final int NO_LWSP
- See Also:
- Constant Field Values
-
state
private MIMEParser.STATE state
-
in
private final java.io.InputStream in
-
bndbytes
private final byte[] bndbytes
-
bl
private final int bl
-
config
private final MIMEConfig config
-
bcs
private final int[] bcs
-
gss
private final int[] gss
-
parsed
private boolean parsed
Have 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 Detail
-
MIMEParser
MIMEParser(java.io.InputStream in, java.lang.String boundary, MIMEConfig config)
-
-
Method Detail
-
iterator
public java.util.Iterator<MIMEEvent> iterator()
Returns iterator for the parsing events. Use the iterator to advance the parsing.- Specified by:
iterator
in interfacejava.lang.Iterable<MIMEEvent>
- Returns:
- iterator for parsing events
-
readHeaders
private InternetHeaders readHeaders()
Collects the headers for the current part by parsing mesage stream.- Returns:
- headers for the current part
-
readBody
private java.nio.ByteBuffer 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
private java.nio.ByteBuffer adjustBuf(int chunkSize, int remaining)
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
private static byte[] getBytes(java.lang.String s)
-
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()
-
-