com.goldeninnovations.smp.messageprocessor
Class FileMessageProcessor

java.lang.Object
  extended by com.goldeninnovations.smp.messageprocessor.FileMessageProcessor
All Implemented Interfaces:
MessageProcessor

public class FileMessageProcessor
extends Object
implements MessageProcessor

Writes all incoming messages to a text file in the specified directory.

Syntax is as follows: From: john.smith@example.com To: john.smith1@example.com To: john.smith2@example.com Data: ...

Files are named using a timestamp "yyyy-MM-dd'T'HH.mm.ss.SSS" plus message counter. Subclass and override getOutputFileName(EmailMessage message) to change naming scheme.


Constructor Summary
FileMessageProcessor(File directory)
          Creates a new FileMessageProcessor using the specified directory to output files.
 
Method Summary
protected  String getOutputFileName(EmailMessage message)
          Returns the filename to be used to write this file to disk.
 void processMessage(EmailMessage message)
          Writes the message to the output directory as an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileMessageProcessor

public FileMessageProcessor(File directory)
                     throws IOException
Creates a new FileMessageProcessor using the specified directory to output files.

The specified directory must exist, otherwise an IOException is thrown.

Parameters:
directory - the output directory, must exist.
Throws:
IOException - thrown if the specified directory does not exist.
Method Detail

processMessage

public void processMessage(EmailMessage message)
Writes the message to the output directory as an XML file.

Specified by:
processMessage in interface MessageProcessor
Parameters:
message - the email message to process.

getOutputFileName

protected String getOutputFileName(EmailMessage message)
Returns the filename to be used to write this file to disk. Defaults to the timestamp + a counter.

OVerride this method in a subclass to change the filename algorithm.

Parameters:
message - the message to save
Returns:
the filename to use.


Copyright © 2010 Eric Daugherty. All Rights Reserved.