Package org.apache.james.mime4j.util

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


        this.state = startState;
        this.endState = endState;
        this.monitor = monitor;
        this.fieldBuilder = fieldBuilder;
        this.bodyDescBuilder = bodyDescBuilder;
        this.linebuf = new ByteArrayBuffer(64);
        this.lineCount = 0;
        this.endOfHeader = false;
        this.headerCount = 0;
        this.lineSource = lineSource;
        this.inbuffer = new BufferedLineReaderInputStream(
View Full Code Here


                return true;
            } catch (MimeException e) {
                monitor(Event.INVALID_HEADER);
                if (config.isMalformedHeaderStartsBody()) {
                    LineReaderInputStream instream = getDataStream();
                    ByteArrayBuffer buf = fieldBuilder.getRaw();
                    // Complain, if raw data is not available or cannot be 'unread'
                    if (buf == null || !instream.unread(buf)) {
                        throw new MimeParseEventException(Event.INVALID_HEADER);
                    }
                    return false;
View Full Code Here

    protected Base64InputStream(int bufsize, InputStream in, DecodeMonitor monitor) {
        if (in == null)
            throw new IllegalArgumentException();
        this.encoded = new byte[bufsize];
        this.decodedBuf = new ByteArrayBuffer(512);
        this.in = in;
        this.monitor = monitor;
    }
View Full Code Here

import junit.framework.TestCase;

public class DefaultFieldBuilderTest extends TestCase {

    static ByteArrayBuffer line(final String line) throws Exception {
        ByteArrayBuffer buf = new ByteArrayBuffer(line.length());
        byte[] b = line.getBytes("US-ASCII");
        buf.append(b, 0, b.length);
        return buf;
    }
View Full Code Here

        DefaultFieldBuilder builder = new DefaultFieldBuilder(0);
        builder.reset();
        builder.append(line("raw:   stuff;\r\n"));
        builder.append(line("   more stuff;\r\n"));
        builder.append(line("   a lot more stuff\r\n"));
        ByteArrayBuffer buf = builder.getRaw();
        assertNotNull(buf);
        assertEquals("raw:   stuff;\r\n   more stuff;\r\n   a lot more stuff\r\n",
                new String(buf.toByteArray(), "US-ASCII"));
        RawField field = builder.build();
        assertNotNull(field);
        assertEquals("raw", field.getName());
        assertEquals("  stuff;   more stuff;   a lot more stuff", field.getBody());
        ByteSequence raw = field.getRaw();
View Full Code Here

        DefaultFieldBuilder builder = new DefaultFieldBuilder(0);
        builder.reset();
        builder.append(line("raw  : stuff;\r\n"));
        builder.append(line("   more stuff;\r\n"));
        builder.append(line("   a lot more stuff\r\n"));
        ByteArrayBuffer buf = builder.getRaw();
        assertNotNull(buf);
        assertEquals("raw  : stuff;\r\n   more stuff;\r\n   a lot more stuff\r\n",
                new String(buf.toByteArray(), "US-ASCII"));
        RawField field = builder.build();
        assertNotNull(field);
        assertEquals("raw", field.getName());
        assertEquals("stuff;   more stuff;   a lot more stuff", field.getBody());
        ByteSequence raw = field.getRaw();
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

            assertEquals(tmp[i], buffer.byteAt(i));
        }
    }

    public void testSetLength() throws Exception {
        ByteArrayBuffer buffer = new ByteArrayBuffer(4);
        buffer.setLength(2);
        assertEquals(2, buffer.length());
    }
View Full Code Here

        DefaultFieldBuilder builder = new DefaultFieldBuilder(0);
        builder.reset();
        builder.append(line("raw:   stuff;\r\n"));
        builder.append(line("   more stuff;\r\n"));
        builder.append(line("   a lot more stuff"));
        ByteArrayBuffer buf = builder.getRaw();
        assertNotNull(buf);
        assertEquals("raw:   stuff;\r\n   more stuff;\r\n   a lot more stuff",
                new String(buf.toByteArray(), "US-ASCII"));
        RawField field = builder.build();
        assertNotNull(field);
        assertEquals("raw", field.getName());
        assertEquals("  stuff;   more stuff;   a lot more stuff", field.getBody());
        ByteSequence raw = field.getRaw();
View Full Code Here

        buffer.setLength(2);
        assertEquals(2, buffer.length());
    }

    public void testSetInvalidLength() throws Exception {
        ByteArrayBuffer buffer = new ByteArrayBuffer(4);
        try {
            buffer.setLength(-2);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
        try {
            buffer.setLength(200);
            fail("IndexOutOfBoundsException should have been thrown");
        } catch (IndexOutOfBoundsException ex) {
            // expected
        }
    }
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.