Class CRLFOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public class CRLFOutputStream
    extends 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 Detail

      • statusLast

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

        protected boolean startOfLine
    • Constructor Detail

      • CRLFOutputStream

        public CRLFOutputStream​(OutputStream out)
        Constructor that wraps an OutputStream.
        Parameters:
        out - the OutputStream to be wrapped
    • Method Detail

      • write

        public void write​(int b)
                   throws IOException
        Writes a byte to the stream Fixes any naked CR or LF to the RFC 2821 mandated CFLF pairing.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        b - the byte to write
        Throws:
        IOException - if an error occurs writing the byte
      • writeChunk

        protected void writeChunk​(byte[] buffer,
                                  int offset,
                                  int length)
                           throws IOException
        Provides an extension point for ExtraDotOutputStream to be able to add dots at the beginning of new lines.
        Parameters:
        buffer - byte buffer
        offset - int offset
        length - and length
        Throws:
        IOException
        See Also:
        FilterOutputStream.write(byte[], int, int)
      • checkCRLFTerminator

        public void checkCRLFTerminator()
                                 throws IOException
        Ensure that the stream is CRLF terminated.
        Throws:
        IOException - if an error occurs writing the byte