org.apache.james.util.stream
Class CRLFOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.apache.james.util.stream.CRLFOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
ExtraDotOutputStream

public class CRLFOutputStream
extends java.io.FilterOutputStream

A Filter for use with SMTP or other protocols in which lines must end with CRLF. Converts every "isolated" occourency of \r or \n with \r\n RFC 2821 #2.3.7 mandates that line termination is CRLF, and that CR and LF must not be transmitted except in that pairing. If we get a naked LF, convert to CRLF.


Field Summary
protected static int LAST_WAS_CR
           
protected static int LAST_WAS_LF
           
protected static int LAST_WAS_OTHER
           
protected  boolean startOfLine
           
protected  int statusLast
          Counter for number of last (0A or 0D).
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
CRLFOutputStream(java.io.OutputStream out)
          Constructor that wraps an OutputStream.
 
Method Summary
 void checkCRLFTerminator()
          Ensure that the stream is CRLF terminated.
 void write(byte[] buffer, int offset, int length)
           
 void write(int b)
          Writes a byte to the stream Fixes any naked CR or LF to the RFC 2821 mandated CFLF pairing.
protected  void writeChunk(byte[] buffer, int offset, int length)
          Provides an extension point for ExtraDotOutputStream to be able to add dots at the beginning of new lines.
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statusLast

protected int statusLast
Counter for number of last (0A or 0D).


LAST_WAS_OTHER

protected static final int LAST_WAS_OTHER
See Also:
Constant Field Values

LAST_WAS_CR

protected static final int LAST_WAS_CR
See Also:
Constant Field Values

LAST_WAS_LF

protected static final int LAST_WAS_LF
See Also:
Constant Field Values

startOfLine

protected boolean startOfLine
Constructor Detail

CRLFOutputStream

public CRLFOutputStream(java.io.OutputStream out)
Constructor that wraps an OutputStream.

Parameters:
out - the OutputStream to be wrapped
Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes a byte to the stream Fixes any naked CR or LF to the RFC 2821 mandated CFLF pairing.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the byte to write
Throws:
java.io.IOException - if an error occurs writing the byte

writeChunk

protected void writeChunk(byte[] buffer,
                          int offset,
                          int length)
                   throws java.io.IOException
Provides an extension point for ExtraDotOutputStream to be able to add dots at the beginning of new lines.

Throws:
java.io.IOException
See Also:
FilterOutputStream.write(byte[], int, int)

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream
Throws:
java.io.IOException
See Also:
FilterOutputStream.write(byte[], int, int)

checkCRLFTerminator

public void checkCRLFTerminator()
                         throws java.io.IOException
Ensure that the stream is CRLF terminated.

Throws:
java.io.IOException - if an error occurs writing the byte


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.