Package org.apache.james.util.stream

Examples of org.apache.james.util.stream.CRLFOutputStream


public class CRLFOutputStreamTest extends TestCase {

    public void testMain() throws IOException {
        String data = ".This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n.doubled?\r\nor not?\n.doubled\nor not?\r\n\r\n\n\n\r\r\r\n";
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        OutputStream os = new CRLFOutputStream(bOut);
        os.write(data.getBytes());
        os.flush();
        String expected = ".This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n.doubled?\r\nor not?\r\n.doubled\r\nor not?\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
        assertEquals(expected,bOut.toString());
    }
View Full Code Here


    /*
     * Test method for 'org.apache.james.util.ExtraDotOutputStream.checkCRLFTerminator()'
     */
    public void testCheckCRLFTerminator() throws IOException {
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        CRLFOutputStream os = new CRLFOutputStream(bOut);
        // if the stream is empty then we should not add the CRLF.
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("",bOut.toString());
        os.write("Test".getBytes());
        os.flush();
        assertEquals("Test",bOut.toString());
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("Test\r\n",bOut.toString());
        // if the stream ends with \r we should simply add the \n
        os.write("A line with incomplete ending\r".getBytes());
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("Test\r\nA line with incomplete ending\r\n",bOut.toString());
        // already correctly terminated, should leave the output untouched
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("Test\r\nA line with incomplete ending\r\n",bOut.toString());
    }
View Full Code Here

    }
   
    public void testMixedSizeChunks() throws IOException {
        String[] data = new String[] {".","This is a test","","\r\n","of the thing.\r","\nWe should not have much trouble.\r","\n",".","doubled?\r\n","or not?\n.","double","d\nor not?\r","\n\r\n","\n\n\r","\r\r\n"};
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        OutputStream os = new CRLFOutputStream(bOut);
        for(int i = 0; i < data.length; i++) {
            os.write(data[i].getBytes());
            os.flush();
        }
        String expected = ".This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n.doubled?\r\nor not?\r\n.doubled\r\nor not?\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
        assertEquals(expected,bOut.toString());
    }
View Full Code Here


    public void testBytePerByte() throws IOException {
        String data = ".This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n.doubled?\r\nor not?\n.doubled\nor not?\r\n\r\n\n\n\r\r\r\n";
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        OutputStream os = new CRLFOutputStream(bOut);
        byte[] buffer = data.getBytes();
        for (int i = 0; i < buffer.length; i++) {
            os.write(buffer[i]);
        }
        os.flush();
        String expected = ".This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n.doubled?\r\nor not?\r\n.doubled\r\nor not?\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
        assertEquals(expected,bOut.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.james.util.stream.CRLFOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.