org.apache.james.mime4j
Class MimeStreamParser

java.lang.Object
  extended by org.apache.james.mime4j.MimeStreamParser

public class MimeStreamParser
extends java.lang.Object

Parses MIME (or RFC822) message streams of bytes or characters and reports parsing events to a ContentHandler instance.

Typical usage:

      ContentHandler handler = new MyHandler();
      MimeStreamParser parser = new MimeStreamParser();
      parser.setContentHandler(handler);
      parser.parse(new BufferedInputStream(new FileInputStream("mime.msg")));
 
NOTE: All lines must end with CRLF (\r\n). If you are unsure of the line endings in your stream you should wrap it in a EOLConvertingInputStream instance.

Version:
$Id: MimeStreamParser.java,v 1.8 2005/02/11 10:12:02 ntherning Exp $

Constructor Summary
MimeStreamParser()
          Creates a new MimeStreamParser instance.
 
Method Summary
 boolean isRaw()
          Determines if this parser is currently in raw mode.
 void parse(java.io.InputStream is)
          Parses a stream of bytes containing a MIME message.
 void setContentHandler(ContentHandler h)
          Sets the ContentHandler to use when reporting parsing events.
 void setRaw(boolean raw)
          Enables or disables raw mode.
 void stop()
          Finishes the parsing and stops reading lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeStreamParser

public MimeStreamParser()
Creates a new MimeStreamParser instance.

Method Detail

parse

public void parse(java.io.InputStream is)
           throws java.io.IOException
Parses a stream of bytes containing a MIME message.

Parameters:
is - the stream to parse.
Throws:
java.io.IOException - on I/O errors.

isRaw

public boolean isRaw()
Determines if this parser is currently in raw mode.

Returns:
true if in raw mode, false otherwise.
See Also:
setRaw(boolean)

setRaw

public void setRaw(boolean raw)
Enables or disables raw mode. In raw mode all future entities (messages or body parts) in the stream will be reported to the ContentHandler.raw(InputStream) handler method only. The stream will contain the entire unparsed entity contents including header fields and whatever is in the body.

Parameters:
raw - true enables raw mode, false disables it.

stop

public void stop()
Finishes the parsing and stops reading lines. NOTE: No more lines will be parsed but the parser will still call ContentHandler.endMultipart(), ContentHandler.endBodyPart(), ContentHandler.endMessage(), etc to match previous calls to ContentHandler.startMultipart(BodyDescriptor), ContentHandler.startBodyPart(), ContentHandler.startMessage(), etc.


setContentHandler

public void setContentHandler(ContentHandler h)
Sets the ContentHandler to use when reporting parsing events.

Parameters:
h - the ContentHandler.


Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.