things.data.processing.rfc822
Class HeaderProcessorv3

java.lang.Object
  extended by java.io.InputStream
      extended by things.data.processing.rfc822.HeaderProcessorv3
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
HttpHeaderProcessor

public abstract class HeaderProcessorv3
extends java.io.InputStream

Processes headers. Read only. Based on v1

Your specific processor will extend this class. The declarations() method will register supported headers with calls to declare(); A call to process() will process a specific message, which will in turn call the other abstract methods for matches (or not-matched). The object can be reused all you want--so keep it around and process() over and over again.

EXAMPLE LEX MATCHING ENGINE

                          
Inputs  beb                                     
                bea                                     
                be                                      

        0       1       2       3       4       5

a       0       0       4       0       0       0
b       1       0       3       0       0       0
c       0       0       0       0       0       0
d       0       0       0       0       0       0
e       0       2       0       0       0       0
f       0       0       0       0       0       0
:       0       0       -3      -1      -2      0

Terms   -1      beb                             
                -2      bea
                -3      be
                -4      

Version:
1.0

Version History

 EPG - Initial (part of toolkit) - 22 NOV 02
 EPG - Modified for this project - 14 FEB 05
 EPG - Forked into a second implementation - 25 MAR 05
 
Author:
Erich P. Gatejen

Field Summary
protected  byte[] headerBuffer
           
protected  int headerBufferLength
           
protected  boolean headerLineBroken
           
static int MAX_HEADER_NAME_SIZE
           
 
Constructor Summary
HeaderProcessorv3()
           
 
Method Summary
 int available()
          Make sure we always report out available, even if it is just the remaining tee character.
 void clearPause()
          Clear a pause (if any) and allow it to move to the next line.
 void close()
          Do not let a user close this stream.
protected abstract  java.util.List<java.lang.String> complete()
          Complete on a specific header.
protected abstract  void declarations()
          All declarations should be put here, so they are done with any initialization.
 void declare(java.lang.String headerName, int id, boolean caseSensitive)
          Declare a header.
 void deplete()
          Deplete current header line.
 void init()
          Reinitialize the processor.
 boolean isDone()
          Is the stream done? Is there anything left in the header?
 boolean isLineBroken()
          Is the line broken?
 boolean isPaused()
          Is the stream paused? Meaning that the current line has been depleted.
 boolean markSupported()
          We do not support mark.
protected abstract  void match(int id)
          This method will be called when a header is matched.
 java.util.List<java.lang.String> process(java.lang.String messageId, java.io.InputStream input)
          Process the headers.
 int read()
          Implement the read method which will be used by header data processors.
protected abstract  void start(java.lang.String messageId)
          Start on a specific header.
protected abstract  void unmatch(byte[] headerBuffer, int size)
          This method will be called when a header is unmatched.
 void writeOriginalHeaderNameWithColon(java.io.OutputStream os)
          Write the original header name with a colon into the given output stream.
 
Methods inherited from class java.io.InputStream
mark, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_HEADER_NAME_SIZE

public static final int MAX_HEADER_NAME_SIZE
See Also:
Constant Field Values

headerLineBroken

protected boolean headerLineBroken

headerBuffer

protected byte[] headerBuffer

headerBufferLength

protected int headerBufferLength
Constructor Detail

HeaderProcessorv3

public HeaderProcessorv3()
                  throws java.lang.Throwable
Throws:
java.lang.Throwable
Method Detail

declarations

protected abstract void declarations()
                              throws java.lang.Throwable
All declarations should be put here, so they are done with any initialization.

Throws:
java.lang.Throwable

start

protected abstract void start(java.lang.String messageId)
                       throws java.lang.Throwable
Start on a specific header. This gives the implementation a chance to initialize.

Parameters:
messageId - the id for the message being processed. The implementation may choose to ignore it.
Throws:
java.lang.Throwable

match

protected abstract void match(int id)
                       throws java.lang.Throwable
This method will be called when a header is matched. Be sure to write to outs if you want anything preserved! This includes the CRLF. The read() method will supply the read of the header line.

Parameters:
id - The defined id.
Throws:
java.lang.Throwable

unmatch

protected abstract void unmatch(byte[] headerBuffer,
                                int size)
                         throws java.lang.Throwable
This method will be called when a header is unmatched. Be sure to write to outs if you want anything preserved! This includes the CRLF. The read() method will supply the read of the header line.

Parameters:
headerBuffer - What we read about the header already.
Throws:
java.lang.Throwable

complete

protected abstract java.util.List<java.lang.String> complete()
                                                      throws java.lang.Throwable
Complete on a specific header. This gives the implementation a chance to return entries. If anything is returned at all is up to the implementation. It can give a null if it wants to.

Returns:
A list of header fields.
Throws:
java.lang.Throwable

declare

public void declare(java.lang.String headerName,
                    int id,
                    boolean caseSensitive)
             throws java.lang.Throwable
Declare a header.

Parameters:
headerName - The header name.
id - The header id. This can be a duplicate. Cannot be =< 0.
caseSensitive - if true, the header name will be case sensitive.
Throws:
java.lang.Throwable

process

public java.util.List<java.lang.String> process(java.lang.String messageId,
                                                java.io.InputStream input)
                                         throws java.lang.Throwable
Process the headers. All headers that are unmatched will be echoed to output. If they are matched, it is up to the subclass to decide to echo them or not.

Parameters:
messageId - The id for the message or document. This may be echoed into the entries, depending on the specific implementation.
input - The input stream.
Returns:
a List of string entries. The type of entries is up to the specific processor.
Throws:
java.lang.Throwable

init

public void init()
          throws java.lang.Throwable
Reinitialize the processor.

Throws:
java.lang.Throwable

writeOriginalHeaderNameWithColon

public void writeOriginalHeaderNameWithColon(java.io.OutputStream os)
                                      throws java.lang.Throwable
Write the original header name with a colon into the given output stream.

Parameters:
os - the stream.
Throws:
java.lang.Throwable

deplete

public void deplete()
             throws java.lang.Throwable
Deplete current header line. It'll just throw it all away.

Throws:
java.lang.Throwable

isLineBroken

public boolean isLineBroken()
Is the line broken?


isPaused

public boolean isPaused()
Is the stream paused? Meaning that the current line has been depleted.

Returns:
true or false

clearPause

public void clearPause()
Clear a pause (if any) and allow it to move to the next line.


isDone

public boolean isDone()
Is the stream done? Is there anything left in the header?

Returns:
true or false

read

public int read()
         throws java.io.IOException
Implement the read method which will be used by header data processors. The header is already ripped and this will just read the rest of the header line.

Specified by:
read in class java.io.InputStream
Returns:
a character or -1 if empty.
Throws:
java.io.IOException

markSupported

public boolean markSupported()
We do not support mark. This will always return false.

Overrides:
markSupported in class java.io.InputStream
Returns:
false no matter what.

close

public void close()
Do not let a user close this stream. So this is a NOOP.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream

available

public int available()
              throws java.io.IOException
Make sure we always report out available, even if it is just the remaining tee character.

Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException


Things.