Package org.apache.james.mime4j.util

Examples of org.apache.james.mime4j.util.ByteArrayBuffer


    public void raw(InputStream is) throws MimeException, IOException {
        throw new UnsupportedOperationException("Not supported");
    }

    private static ByteSequence loadStream(InputStream in) throws IOException {
        ByteArrayBuffer bab = new ByteArrayBuffer(64);

        int b;
        while ((b = in.read()) != -1) {
            bab.append(b);
        }

        return bab;
    }
View Full Code Here


        this.state = startState;
        this.startState = startState;
        this.endState = endState;
        this.config = config;
        this.body = newBodyDescriptor(parent);
        this.linebuf = new ByteArrayBuffer(64);
        this.lineCount = 0;
        this.endOfHeader = false;
        this.headerCount = 0;
    }
View Full Code Here

        if (endOfHeader)
            throw new IllegalStateException();

        int maxLineLen = config.getMaxLineLen();
        LineReaderInputStream instream = getDataStream();
        ByteArrayBuffer fieldbuf = new ByteArrayBuffer(64);

        for (;;) {
            // If there's still data stuck in the line buffer
            // copy it to the field buffer
            int len = linebuf.length();
            if (maxLineLen > 0 && fieldbuf.length() + len >= maxLineLen) {
                throw new MaxLineLimitException("Maximum line length limit exceeded");
            }
            if (len > 0) {
                fieldbuf.append(linebuf.buffer(), 0, len);
            }
            linebuf.clear();
            if (instream.readLine(linebuf) == -1) {
                monitor(Event.HEADERS_PREMATURE_END);
                endOfHeader = true;
View Full Code Here

            }
            if (headerCount >= maxHeaderLimit) {
                throw new MaxHeaderLimitException("Maximum header limit exceeded");
            }

            ByteArrayBuffer fieldbuf = fillFieldBuffer();
            headerCount++;

            // Strip away line delimiter
            int len = fieldbuf.length();
            if (len > 0 && fieldbuf.byteAt(len - 1) == '\n') {
                len--;
            }
            if (len > 0 && fieldbuf.byteAt(len - 1) == '\r') {
                len--;
            }
            fieldbuf.setLength(len);
           
            boolean valid = true;
           
            int pos = fieldbuf.indexOf((byte) ':');
            if (pos <= 0) {
                monitor(Event.INALID_HEADER);
                valid = false;
            } else {
                for (int i = 0; i < pos; i++) {
                    if (!fieldChars.get(fieldbuf.byteAt(i) & 0xff)) {
                        monitor(Event.INALID_HEADER);
                        valid = false;
                        break;
                    }
                }
View Full Code Here

    }

    private void writeBytes(ByteSequence byteSequence, OutputStream out)
            throws IOException {
        if (byteSequence instanceof ByteArrayBuffer) {
            ByteArrayBuffer bab = (ByteArrayBuffer) byteSequence;
            out.write(bab.buffer(), 0, bab.length());
        } else {
            out.write(byteSequence.toByteArray());
        }
    }
View Full Code Here

        String teststr = "1234567890\r\n";
        byte[] raw = teststr.getBytes("US-ASCII");
       
        LineReaderInputStream instream1 = new BufferedLineReaderInputStream(
                new ByteArrayInputStream(raw), 1024, 13);
        ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
        linebuf.clear();
        instream1.readLine(linebuf);

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

        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

        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

        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

        }
        byte[] raw = outstream.toByteArray();
       
        BufferedLineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 16);
       
        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

TOP

Related Classes of org.apache.james.mime4j.util.ByteArrayBuffer

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.