|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
things.data.processing.rfc822.HeaderProcessorv2
public abstract class HeaderProcessorv2
Processes headers. VERSION 2
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.
This one properly calls headersComplete after the final header and before any terminating CF/LF (or whatever). HOWEVER! It may leave CRs and LFs from the header in the InputStream. Adding lookahead for that would be a giant pain in the ass and really slow things down on the other side. So, any body processor needs to make sure it reads and writes these characters, just emits a CR/LF itself before eating any dangling header whitespace, or something in between.
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 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 EPG - Actually fixed - 1 APRIL 06
Field Summary | |
---|---|
protected byte[] |
headerBuffer
|
protected int |
headerBufferLength
|
protected boolean |
headerLineBroken
|
static int |
MAX_HEADER_NAME_SIZE
|
Constructor Summary | |
---|---|
HeaderProcessorv2()
|
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(java.io.OutputStream out)
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. |
java.lang.String |
getHeaderName()
Get the header name. |
protected abstract void |
headersComplete(java.io.OutputStream out)
The headers are done. |
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,
java.io.OutputStream out)
This method will be called when a header is matched. |
protected abstract void |
matchReadOnly(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,
java.io.OutputStream output)
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,
java.io.OutputStream out)
This method will be called when a header is unmatched. |
void |
writeOriginalHeaderNameWithColon()
Write the original header name with a colon. |
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 |
---|
public static final int MAX_HEADER_NAME_SIZE
protected boolean headerLineBroken
protected byte[] headerBuffer
protected int headerBufferLength
Constructor Detail |
---|
public HeaderProcessorv2() throws java.lang.Throwable
java.lang.Throwable
Method Detail |
---|
protected abstract void declarations() throws java.lang.Throwable
java.lang.Throwable
protected abstract void start(java.lang.String messageId) throws java.lang.Throwable
messageId
- the id for the message being processed. The implementation may choose to ignore it.
java.lang.Throwable
protected abstract void match(int id, java.io.OutputStream out) throws java.lang.Throwable
id
- The defined id.out
- OutputStream to write the processed data.
java.lang.Throwable
protected abstract void unmatch(byte[] headerBuffer, int size, java.io.OutputStream out) throws java.lang.Throwable
out
- OutputStream to write the processed data.headerBuffer
- What we read about the header already.
java.lang.Throwable
protected abstract void matchReadOnly(int id) throws java.lang.Throwable
id
- The defined id.
java.lang.Throwable
protected abstract void headersComplete(java.io.OutputStream out) throws java.lang.Throwable
out
- OutputStream to write the processed data.
java.lang.Throwable
protected abstract java.util.List<java.lang.String> complete(java.io.OutputStream out) throws java.lang.Throwable
out
- OutputStream to write the processed data.
java.lang.Throwable
public void declare(java.lang.String headerName, int id, boolean caseSensitive) throws java.lang.Throwable
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.
java.lang.Throwable
public java.util.List<java.lang.String> process(java.lang.String messageId, java.io.InputStream input, java.io.OutputStream output) throws java.lang.Throwable
messageId
- The id for the message or document. This may be echoed into the entries, depending on the specific implementation.input
- The input stream.output
- The output stream. Set to null if this is a read only process.
java.lang.Throwable
public void init() throws java.lang.Throwable
java.lang.Throwable
public void writeOriginalHeaderNameWithColon() throws java.lang.Throwable
java.lang.Throwable
public void writeOriginalHeaderNameWithColon(java.io.OutputStream os) throws java.lang.Throwable
os
- the stream.
java.lang.Throwable
public java.lang.String getHeaderName() throws java.lang.Throwable
java.lang.Throwable
public void deplete() throws java.lang.Throwable
java.lang.Throwable
public boolean isLineBroken()
public boolean isPaused()
public void clearPause()
public boolean isDone()
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public boolean markSupported()
markSupported
in class java.io.InputStream
public void close()
close
in interface java.io.Closeable
close
in class java.io.InputStream
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |