Class 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<MIMEEvent> it = parser.iterator();
     while(it.hasNext()) {
       MIMEEvent event = it.next();
       ...
     }
     
    • 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 capacity
      private 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
      • Methods 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 Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • in

        private final java.io.InputStream in
      • bndbytes

        private final byte[] bndbytes
      • bl

        private final int bl
      • 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 interface java.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 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​(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 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()