Package org.apache.james.mime4j.io

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


    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.byteAt(1);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException expected) {
        }
        try {
            inbuffer.byteAt(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


            bufferSize = 4096;
        }
        try {
            if (mimeStream != null) {
                mimeStream = new MimeBoundaryInputStream(
                        new BufferedLineReaderInputStream(mimeStream, bufferSize), boundary);
            } else {
                inbuffer.ensureCapacity(bufferSize);
                mimeStream = new MimeBoundaryInputStream(inbuffer, boundary);
            }
        } catch (IllegalArgumentException e) {
View Full Code Here

            RawEntity message = new RawEntity(instream);
            return message;
        } else {
            MimeEntity message = new MimeEntity(
                    rootStream,
                    new BufferedLineReaderInputStream(instream, 4 * 1024),
                    body,
                    EntityStates.T_START_MESSAGE,
                    EntityStates.T_END_MESSAGE,
                    maximalBodyDescriptor,
                    strictParsing);
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);
            MimeEntity mimeentity = new MimeEntity(
                    rootStream,
                    stream,
                    body,
                    EntityStates.T_START_BODYPART,
View Full Code Here

    }

    private void doParse(InputStream stream, String contentType) {
        entities.clear();
        rootInputStream = new RootInputStream(stream);
        inbuffer = new BufferedLineReaderInputStream(rootInputStream, 4 * 1024);
        switch (recursionMode) {
        case M_RAW:
            RawEntity rawentity = new RawEntity(inbuffer);
            currentStateMachine = rawentity;
            break;
View Full Code Here

        String text = "Line 1\r\nLine 2\r\n--boundary\r\n" +
                "Line 3\r\nLine 4\r\n--boundary--";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
       
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
       
        MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals("Line 1\r\nLine 2", read(mime1, 5));
       
        assertFalse(mime1.isLastPart());
View Full Code Here

        String text = "Line 1\r\nLine 2\n--boundary\n" +
                "Line 3\r\nLine 4\n--boundary--\n";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
       
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
       
        MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals("Line 1\r\nLine 2", read(mime1, 5));
       
        assertFalse(mime1.isLastPart());
View Full Code Here

        String text = "yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada\r\n--boundary\r\n" +
                "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah\r\n--boundary--";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
       
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 20);
       
        MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals("yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada",
                read(mime1, 10));
       
View Full Code Here

        String text = "yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada\r\n--boundary\r\n" +
                "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah\r\n--boundary--";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
       
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 20);
       
        MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
       
        assertEquals("yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada",
                read(mime1, 25));
View Full Code Here

        String text = "Line 1\r\nLine 2\r\n--boundary\r\n" +
                "Line 3\r\nLine 4\r\n--boundary--";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
       
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
       
        MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals("Line 1\r\nLine 2", readByOneByte(mime1));
       
        assertFalse(mime1.isLastPart());
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.