Class MIMEParser

java.lang.Object
org.jvnet.mimepull.MIMEParser
All Implemented Interfaces:
Iterable<MIMEEvent>

class MIMEParser extends Object implements 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<MIMEEvent> it = parser.iterator();
 while(it.hasNext()) {
   MIMEEvent event = it.next();
   ...
 }
 
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • HEADER_ENCODING

      private static final String HEADER_ENCODING
      See Also:
    • NO_LWSP

      private static final int NO_LWSP
      See Also:
    • state

      private MIMEParser.STATE state
    • in

      private final 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 Details

  • Method Details

    • iterator

      public Iterator<MIMEEvent> iterator()
      Returns iterator for the parsing events. Use the iterator to advance the parsing.
      Specified by:
      iterator in interface 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 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 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 bytes
      remaining - 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(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 mybuf
      off - start index in mybuf
      len - 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()