Package org.apache.james.mime4j.io

Examples of org.apache.james.mime4j.io.BufferedLineReaderInputStream


    public void testReadEmptyLine() throws Exception {
       
        String teststr = "\n\n\r\n\r\r\n\n\n\n\n\n";
        byte[] raw = teststr.getBytes("US-ASCII");
       
        LineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 4);
       
        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        linebuf.clear();
        instream.readLine(linebuf);
        String s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);
       
        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);
       
        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\r\n", s);

        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\r\r\n", s);

        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);

        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);

        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);

        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);

        linebuf.clear();
        instream.readLine(linebuf);
        s = new String(linebuf.toByteArray(), "US-ASCII");
        assertEquals("\n", s);

        assertEquals(-1, instream.readLine(linebuf));
        assertEquals(-1, instream.readLine(linebuf));
    }
View Full Code Here


            LineNumberInputStream lineInput = new LineNumberInputStream(stream);
            lineSource = lineInput;
            stream = lineInput;
        }

        inbuffer = new BufferedLineReaderInputStream(
                stream,
                4 * 1024,
                config.getMaxLineLen());
        switch (recursionMode) {
        case M_RAW:
View Full Code Here

            bufferSize = 4096;
        }
        try {
            if (mimeStream != null) {
                mimeStream = new MimeBoundaryInputStream(
                        new BufferedLineReaderInputStream(
                                mimeStream,
                                bufferSize,
                                config.getMaxLineLen()),
                        boundary);
            } else {
View Full Code Here

            RawEntity message = new RawEntity(instream);
            return message;
        } else {
            MimeEntity message = new MimeEntity(
                    lineSource,
                    new BufferedLineReaderInputStream(
                            instream,
                            4 * 1024,
                            config.getMaxLineLen()),
                    body,
                    EntityStates.T_START_MESSAGE,
View Full Code Here

    private EntityStateMachine nextMimeEntity() {
        if (recursionMode == RecursionMode.M_RAW) {
            RawEntity message = new RawEntity(mimeStream);
            return message;
        } else {
            BufferedLineReaderInputStream stream = new BufferedLineReaderInputStream(
                    mimeStream,
                    4 * 1024,
                    config.getMaxLineLen());
            MimeEntity mimeentity = new MimeEntity(
                    lineSource,
View Full Code Here

    public void testInvalidInput() throws Exception {
        String text = "blah blah yada yada";
        byte[] b1 = text.getBytes("US-ASCII");
        String pattern = "blah";
        byte[] b2 = pattern.getBytes("US-ASCII");
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
        inbuffer.fillBuffer();
       
        assertEquals('b', inbuffer.read());
        assertEquals('l', inbuffer.read());
       
        try {
            inbuffer.charAt(1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.charAt(20);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf(b2, -1, 3);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf(b2, 1, 3);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf(b2, 2, -1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf(b2, 2, 18);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        assertEquals(5, inbuffer.indexOf(b2, 2, 17));
        try {
            inbuffer.indexOf((byte)' ', -1, 3);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf((byte)' ', 1, 3);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf((byte)' ', 2, -1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.indexOf((byte)' ', 2, 18);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        assertEquals(10, inbuffer.indexOf((byte)'y', 2, 17));
    }
View Full Code Here

    }
     
    public void testBasicOperations() throws Exception {
        String text = "bla bla yada yada haha haha";
        byte[] b1 = text.getBytes("US-ASCII");
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
        inbuffer.fillBuffer();
        assertEquals(0, inbuffer.pos());
        assertEquals(27, inbuffer.limit());
        assertEquals(27, inbuffer.length());

        inbuffer.read();
        inbuffer.read();

        assertEquals(2, inbuffer.pos());
        assertEquals(27, inbuffer.limit());
        assertEquals(25, inbuffer.length());
       
        byte[] tmp1 = new byte[3];
        assertEquals(3, inbuffer.read(tmp1));

        assertEquals(5, inbuffer.pos());
        assertEquals(27, inbuffer.limit());
        assertEquals(22, inbuffer.length());
       
        byte[] tmp2 = new byte[22];
        assertEquals(22, inbuffer.read(tmp2));

        assertEquals(27, inbuffer.pos());
        assertEquals(27, inbuffer.limit());
        assertEquals(0, inbuffer.length());

        assertEquals(-1, inbuffer.read(tmp1));
        assertEquals(-1, inbuffer.read(tmp1));
        assertEquals(-1, inbuffer.read());
        assertEquals(-1, inbuffer.read());
    }
View Full Code Here

    public void testPatternMatching1() throws Exception {
        String text = "blabla d is the word";
        String pattern = "d";
        byte[] b1 = text.getBytes("US-ASCII");
        byte[] b2 = pattern.getBytes("US-ASCII");
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
        inbuffer.fillBuffer();
        int i = inbuffer.indexOf(b2);
        assertEquals(7, i);
    }
View Full Code Here

    public void testPatternMatching2() throws Exception {
        String text = "disddisdissdsidsidsiid";
        String pattern = "siid";
        byte[] b1 = text.getBytes("US-ASCII");
        byte[] b2 = pattern.getBytes("US-ASCII");
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
        inbuffer.fillBuffer();
        int i = inbuffer.indexOf(b2);
        assertEquals(18, i);
    }
View Full Code Here

    public void testPatternMatching3() throws Exception {
        String text = "bla bla yada yada haha haha";
        String pattern = "blah";
        byte[] b1 = text.getBytes("US-ASCII");
        byte[] b2 = pattern.getBytes("US-ASCII");
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
        inbuffer.fillBuffer();
        int i = inbuffer.indexOf(b2);
        assertEquals(-1, i);
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.io.BufferedLineReaderInputStream

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.