Package org.apache.james.mime4j.io

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


            int endState,
            MimeEntityConfig config) {
        super(parent, startState, endState, config);
        this.rootStream = rootStream;
        this.inbuffer = inbuffer;
        this.dataStream = new LineReaderInputStreamAdaptor(
                inbuffer,
                config.getMaxLineLen());
        this.skipHeader = false;
    }
View Full Code Here


            }
        } catch (IllegalArgumentException e) {
            // thrown when boundary is too long
            throw new MimeException(e.getMessage(), e);
        }
        dataStream = new LineReaderInputStreamAdaptor(
                mimeStream,
                config.getMaxLineLen());
    }
View Full Code Here

                config.getMaxLineLen());
    }
   
    private void clearMimeStream() {
        mimeStream = null;
        dataStream = new LineReaderInputStreamAdaptor(
                inbuffer,
                config.getMaxLineLen());
    }
View Full Code Here

    public void testBasicOperations() throws Exception {
        String text = "ah blahblah";
        byte[] b1 = text.getBytes("US-ASCII");
       
        LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(b1));
       
        assertEquals((byte)'a', instream.read());
        assertEquals((byte)'h', instream.read());
        assertEquals((byte)' ', instream.read());

        byte[] tmp1 = new byte[4];
        assertEquals(4, instream.read(tmp1));
        assertEquals(4, instream.read(tmp1));

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

        for (int i = 0; i < teststrs.length; i++) {
            outstream.write(teststrs[i].getBytes("US-ASCII"));
        }
        byte[] raw = outstream.toByteArray();
       
        LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(raw));
       
        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        for (int i = 0; i < teststrs.length; i++) {
            linebuf.clear();
            instream.readLine(linebuf);
            String s = new String(linebuf.toByteArray(), "US-ASCII");
            assertEquals(teststrs[i], s);
        }
        assertEquals(-1, instream.readLine(linebuf));
        assertEquals(-1, instream.readLine(linebuf));
    }
View Full Code Here

    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");
       
        LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(raw));
       
        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

    public void testReadEmptyLineMaxLimit() throws Exception {
       
        String teststr = "1234567890\r\n";
        byte[] raw = teststr.getBytes("US-ASCII");
       
        LineReaderInputStreamAdaptor instream1 = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(raw), 13);
        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        linebuf.clear();
        instream1.readLine(linebuf);

        LineReaderInputStreamAdaptor instream2 = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(raw), 12);
        linebuf.clear();
        try {
            instream2.readLine(linebuf);
            fail("MaxLineLimitException should have been thrown");
        } catch (MaxLineLimitException ex) {
        }
    }
View Full Code Here

    public void testBasicOperations() throws Exception {
        String text = "ah blahblah";
        byte[] b1 = text.getBytes("US-ASCII");

        LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(b1));

        assertEquals((byte)'a', instream.read());
        assertEquals((byte)'h', instream.read());
        assertEquals((byte)' ', instream.read());

        byte[] tmp1 = new byte[4];
        assertEquals(4, instream.read(tmp1));
        assertEquals(4, instream.read(tmp1));

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

        for (String teststr : teststrs) {
            outstream.write(teststr.getBytes("US-ASCII"));
        }
        byte[] raw = outstream.toByteArray();

        LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(raw));

        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        for (String teststr : teststrs) {
            linebuf.clear();
            instream.readLine(linebuf);
            String s = new String(linebuf.toByteArray(), "US-ASCII");
            assertEquals(teststr, s);
        }
        assertEquals(-1, instream.readLine(linebuf));
        assertEquals(-1, instream.readLine(linebuf));
    }
View Full Code Here

    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");

        LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
                new ByteArrayInputStream(raw));

        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

TOP

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

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.