Package org.apache.james.mime4j.io

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


        String text = "Line 1\r\nLine 2\r\n--boundary\r\n" +
                "Line 3\r\nLine 4\r\n\r\n--boundary\r\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


     */
    public void testImmediateBoundary() throws IOException {
        String text = "--boundary\r\n";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
       
        MimeBoundaryInputStream stream =
            new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals(-1, stream.read());
       
        text = "\r\n--boundary\r\n";
       
        bis = new ByteArrayInputStream(text.getBytes());
        buffer = new BufferedLineReaderInputStream(bis, 4096);
        stream =
            new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals(-1, stream.read());
    }
View Full Code Here

     */
    public void testHasMoreParts() throws IOException {
        String text = "--boundary--\r\n";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
        MimeBoundaryInputStream stream =
            new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals(-1, stream.read());
        assertTrue(stream.isLastPart());
    }
View Full Code Here

     */
    public void testPrefixIsBoundary() throws IOException {
        String text = "Line 1\r\n\r\n--boundaryyada\r\n";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
        MimeBoundaryInputStream stream =
            new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals("Line 1\r\n", read(stream, 100));
       
        text = "--boundaryyada\r\n";
       
        bis = new ByteArrayInputStream(text.getBytes());
        buffer = new BufferedLineReaderInputStream(bis, 4096);
        stream = new MimeBoundaryInputStream(buffer, "boundary");
        assertEquals(-1, stream.read());
    }
View Full Code Here

            outstream.write(teststrs[i].getBytes("US-ASCII"));
        }
        outstream.write(term.getBytes("US-ASCII"));
        byte[] raw = outstream.toByteArray();
       
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 20);
        LineReaderInputStream instream = new MimeBoundaryInputStream(inbuffer, "1234");
       
        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        for (int i = 0; i < teststrs.length; i++) {
            linebuf.clear();
View Full Code Here

    public void testReadEmptyLine() throws Exception {
       
        String teststr = "01234567890123456789\n\n\r\n\r\r\n\n\n\n\n\n--1234\r\n";
        byte[] raw = teststr.getBytes("US-ASCII");
       
        BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 20);
        LineReaderInputStream instream = new MimeBoundaryInputStream(inbuffer, "1234");
       
        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        linebuf.clear();
        instream.readLine(linebuf);
View Full Code Here

   
    public void testboundaryLongerThanBuffer() throws IOException {
        String text = "--looooooooooooooooooooooooooong-boundary\r\n";
       
        ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
        BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 10);
       
        try {
            new MimeBoundaryInputStream(buffer, "looooooooooooooooooooooooooong-boundary");
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException expected) {
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

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.