Package org.apache.http.impl.nio.reactor

Examples of org.apache.http.impl.nio.reactor.SessionOutputBuffer


            linebuffersize = 512;
        }
       
        this.inbuf = new SessionInputBuffer(buffersize, linebuffersize);
        this.inbuf.reset(params);
        this.outbuf = new SessionOutputBuffer(buffersize, linebuffersize);
        this.outbuf.reset(params);
        this.lineBuffer = new CharArrayBuffer(64);
       
        this.incomingContentStrategy = new LaxContentLengthStrategy();
        this.outgoingContentStrategy = new StrictContentLengthStrategy();
View Full Code Here


        assertFalse(inbuf.readLine(line, true));
    }
   
    public void testWriteLineChunks() throws Exception {
       
        SessionOutputBuffer outbuf = new SessionOutputBuffer(16, 16);
        SessionInputBuffer inbuf = new SessionInputBuffer(16, 16);
       
        ReadableByteChannel inChannel = newChannel("One\r\nTwo\r\nThree");
       
        inbuf.fill(inChannel);
       
        CharArrayBuffer line = new CharArrayBuffer(64);
       
        line.clear();
        assertTrue(inbuf.readLine(line, false));
        assertEquals("One", line.toString());
       
        outbuf.writeLine(line);
       
        line.clear();
        assertTrue(inbuf.readLine(line, false));
        assertEquals("Two", line.toString());

        outbuf.writeLine(line);
       
        line.clear();
        assertFalse(inbuf.readLine(line, false));

        inChannel = newChannel("\r\nFour");
        inbuf.fill(inChannel);

        line.clear();
        assertTrue(inbuf.readLine(line, false));
        assertEquals("Three", line.toString());

        outbuf.writeLine(line);
       
        inbuf.fill(inChannel);
       
        line.clear();
        assertTrue(inbuf.readLine(line, true));
        assertEquals("Four", line.toString());

        outbuf.writeLine(line);
       
        line.clear();
        assertFalse(inbuf.readLine(line, true));

        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        WritableByteChannel outChannel = newChannel(outstream);
        outbuf.flush(outChannel);
       
        String s = new String(outstream.toByteArray(), "US-ASCII");
        assertEquals("One\r\nTwo\r\nThree\r\nFour\r\n", s);
    }
View Full Code Here

        buffer.append("and stuff like that");
        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 16);
        for (int i = 0; i < teststrs.length; i++) {
            outbuf.writeLine(teststrs[i]);
        }
        //this write operation should have no effect
        outbuf.writeLine((String)null);
        outbuf.writeLine((CharArrayBuffer)null);
       
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        WritableByteChannel outChannel = newChannel(outstream);
        outbuf.flush(outChannel);

        ReadableByteChannel channel = newChannel(outstream.toByteArray());
       
        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 16);
        inbuf.fill(channel);
View Full Code Here

        assertNull(inbuf.readLine(true));
        assertNull(inbuf.readLine(true));
    }

    public void testComplexReadWriteLine() throws Exception {
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 16);
        outbuf.write(ByteBuffer.wrap(new byte[] {'a', '\n'}));
        outbuf.write(ByteBuffer.wrap(new byte[] {'\r', '\n'}));
        outbuf.write(ByteBuffer.wrap(new byte[] {'\r', '\r', '\n'}));
        outbuf.write(ByteBuffer.wrap(new byte[] {'\n'}));
       
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < 14; i++) {
            buffer.append("a");
        }
        String s1 = buffer.toString();
        buffer.append("\r\n");
        outbuf.write(ByteBuffer.wrap(buffer.toString().getBytes("US-ASCII")));

        buffer.setLength(0);
        for (int i = 0; i < 15; i++) {
            buffer.append("a");
        }
        String s2 = buffer.toString();
        buffer.append("\r\n");
        outbuf.write(ByteBuffer.wrap(buffer.toString().getBytes("US-ASCII")));

        buffer.setLength(0);
        for (int i = 0; i < 16; i++) {
            buffer.append("a");
        }
        String s3 = buffer.toString();
        buffer.append("\r\n");
        outbuf.write(ByteBuffer.wrap(buffer.toString().getBytes("US-ASCII")));

        outbuf.write(ByteBuffer.wrap(new byte[] {'a'}));
       
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        WritableByteChannel outChannel = newChannel(outstream);
        outbuf.flush(outChannel);

        ReadableByteChannel channel = newChannel(outstream.toByteArray());

        SessionInputBuffer inbuf = new SessionInputBuffer(1024, 16);
        inbuf.fill(channel);
View Full Code Here

        String s3 = "Like hello and stuff";
       
        HttpParams params = new BasicHttpParams(null);
        HttpProtocolParams.setHttpElementCharset(params, "UTF-8");
       
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 16);
        outbuf.reset(params);
       
        for (int i = 0; i < 10; i++) {
            outbuf.writeLine(s1);
            outbuf.writeLine(s2);
            outbuf.writeLine(s3);
        }
       
        ByteArrayOutputStream outstream = new ByteArrayOutputStream();
        WritableByteChannel outChannel = newChannel(outstream);
        outbuf.flush(outChannel);

        byte[] tmp = outstream.toByteArray();
       
        ReadableByteChannel channel = newChannel(tmp);       
        SessionInputBuffer inbuf = new SessionInputBuffer(16, 16);
View Full Code Here

    private static WritableByteChannel newChannel(final ByteArrayOutputStream baos) {
        return Channels.newChannel(baos);
    }
   
    public void testBasicCoding() throws Exception {
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 128);
        ChunkEncoder encoder = new ChunkEncoder(outbuf);
       
        encoder.write(wrap("12345"));
        encoder.write(wrap("678"));
        encoder.write(wrap("90"));
        encoder.complete();
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        outbuf.flush(newChannel(baos));
       
        String s = baos.toString("US-ASCII");
       
        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
View Full Code Here

        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
    }

    public void testCodingEmptyBuffer() throws Exception {
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 128);
        ChunkEncoder encoder = new ChunkEncoder(outbuf);
       
        encoder.write(wrap("12345"));
        encoder.write(wrap("678"));
        encoder.write(wrap("90"));
       
        ByteBuffer empty = ByteBuffer.allocate(100);
        empty.flip();
        encoder.write(empty);
        encoder.write(null);
       
        encoder.complete();
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        outbuf.flush(newChannel(baos));
       
        String s = baos.toString("US-ASCII");
       
        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
View Full Code Here

        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
    }

    public void testCodingCompleted() throws Exception {
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 128);
        ChunkEncoder encoder = new ChunkEncoder(outbuf);
       
        encoder.write(wrap("12345"));
        encoder.write(wrap("678"));
        encoder.write(wrap("90"));
View Full Code Here

    private static WritableByteChannel newChannel(final ByteArrayOutputStream baos) {
        return Channels.newChannel(baos);
    }
   
    public void testBasicCoding() throws Exception {
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 128);
        ChunkEncoder encoder = new ChunkEncoder(outbuf);
       
        encoder.write(wrap("12345"));
        encoder.write(wrap("678"));
        encoder.write(wrap("90"));
        encoder.complete();
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        outbuf.flush(newChannel(baos));
       
        String s = baos.toString("US-ASCII");
       
        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
View Full Code Here

        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
    }

    public void testCodingEmptyBuffer() throws Exception {
        SessionOutputBuffer outbuf = new SessionOutputBuffer(1024, 128);
        ChunkEncoder encoder = new ChunkEncoder(outbuf);
       
        encoder.write(wrap("12345"));
        encoder.write(wrap("678"));
        encoder.write(wrap("90"));
       
        ByteBuffer empty = ByteBuffer.allocate(100);
        empty.flip();
        encoder.write(empty);
        encoder.write(null);
       
        encoder.complete();
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        outbuf.flush(newChannel(baos));
       
        String s = baos.toString("US-ASCII");
       
        assertTrue(encoder.isCompleted());
        assertEquals("5\r\n12345\r\n3\r\n678\r\n2\r\n90\r\n0\r\n\r\n", s);
View Full Code Here

TOP

Related Classes of org.apache.http.impl.nio.reactor.SessionOutputBuffer

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.