Examples of CRLFOutputStream


Examples of com.sun.xml.wss.util.CRLFOutputStream

        } catch (IOException e) {                       
            log.log(Level.SEVERE, "WSS1002.error.canonicalizing.textplain",
                    new Object[] {e.getMessage()});
            throw new javax.xml.crypto.dsig.TransformException(e);
        }
        CRLFOutputStream crlfOutStream = null;
        ByteArrayOutputStream bout = null;
        if(outputStream == null){
            bout = new ByteArrayOutputStream();
            crlfOutStream = new CRLFOutputStream(bout);
        }else{
            crlfOutStream = new CRLFOutputStream(outputStream);
        }
       
        while(len > 0){
            try {
                crlfOutStream.write(data,0,len);
                len = input.read(data);
            } catch (IOException e) {
                log.log(Level.SEVERE, "WSS1002.error.canonicalizing.textplain",
                    new Object[] {e.getMessage()});
                throw new javax.xml.crypto.dsig.TransformException(e);
View Full Code Here

Examples of com.sun.xml.wss.util.CRLFOutputStream

     * ending normalization to <CR><LF>.
     * Section 4.1.1. [RFC 2046]
     */
    public byte[] canonicalize(byte[] inputBytes) throws XWSSecurityException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        CRLFOutputStream crlfOutStream = new CRLFOutputStream(bout);
        try {
            crlfOutStream.write(inputBytes);
        } catch (IOException e) {
            log.log(Level.SEVERE, "WSS1002.error.canonicalizing.textplain",
                    new Object[] {e.getMessage()});
            throw new XWSSecurityException(e);
        }
View Full Code Here

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

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

    /*
     * 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

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

    }
   
    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

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


    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

Examples of org.apache.wss4j.common.util.CRLFOutputStream

public class CRLFOutputStreamTest {

    @org.junit.Test
    public void testBytePerByte() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        CRLFOutputStream crlfOutputStream = new CRLFOutputStream(baos);
        crlfOutputStream.write('\n');
        crlfOutputStream.write('\r');
        crlfOutputStream.write('\r');
        crlfOutputStream.write('\n');
        crlfOutputStream.write('\n');
        crlfOutputStream.write('\n');
        crlfOutputStream.write('\r');
        crlfOutputStream.write('\r');
        crlfOutputStream.write('\r');
        crlfOutputStream.write('a');
        crlfOutputStream.write('\n');
        crlfOutputStream.write('\r');
        crlfOutputStream.write('\n');
        crlfOutputStream.write('a');
        crlfOutputStream.write('a');
        crlfOutputStream.write('a');
        crlfOutputStream.close();
        Assert.assertArrayEquals("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\na\r\n\r\naaa".getBytes(), baos.toByteArray());
    }
View Full Code Here

Examples of org.apache.wss4j.common.util.CRLFOutputStream

    }

    @org.junit.Test
    public void testBytes() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        CRLFOutputStream crlfOutputStream = new CRLFOutputStream(baos);
        crlfOutputStream.write("\n\r\r\n\n\n\r\r\ra\n\r\naaa".getBytes());
        crlfOutputStream.close();
        Assert.assertArrayEquals("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\na\r\n\r\naaa".getBytes(), baos.toByteArray());
    }
View Full Code Here

Examples of org.apache.wss4j.common.util.CRLFOutputStream

    }

    @org.junit.Test
    public void testBytes1() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        CRLFOutputStream crlfOutputStream = new CRLFOutputStream(baos);
        crlfOutputStream.write("aaaaaaaaaa".getBytes());
        crlfOutputStream.close();
        Assert.assertArrayEquals("aaaaaaaaaa".getBytes(), baos.toByteArray());
    }
View Full Code Here

Examples of org.apache.wss4j.common.util.CRLFOutputStream

    public void testRandom() throws Exception {
        byte[] pool = new byte[] {'\r', '\n', 'a'};
        Random random = new Random();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        CRLFOutputStream crlfOutputStream = new CRLFOutputStream(baos);

        ByteArrayOutputStream testString = new ByteArrayOutputStream();

        for (int h = 0; h < 10000; h++) {
            if (random.nextBoolean()) {
                byte b = pool[random.nextInt(pool.length)];
                testString.write(b);
                crlfOutputStream.write(b);
            } else {
                int byteCount = random.nextInt(1000);
                byte[] bytes = new byte[byteCount];
                for (int i = 0; i < byteCount; i++) {
                     bytes[i] = pool[random.nextInt(pool.length)];
                }
                testString.write(bytes);
                crlfOutputStream.write(bytes);
            }
        }

        crlfOutputStream.close();
        byte[] res = baos.toByteArray();
        for (int i = 0; i < res.length; i++) {
            byte re = res[i];
            if (re == '\r') {
                if (res[i + 1] != '\n') {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.