Examples of SessionOutputBuffer


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

   
    public void testCodingEmptyBuffer() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);
        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();

        IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
        encoder.write(wrap("stuff"));
       
View Full Code Here

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

    public void testCodingCompleted() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);
        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();

        IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics);
        encoder.write(wrap("stuff"));
        encoder.complete();
View Full Code Here

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

    public void testInvalidConstructor() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);

        try {
            new IdentityEncoder(null, null, null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
View Full Code Here

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

    }
   
    public void testWriteLineChunks() throws Exception {
       
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(16, 16, params);
        SessionInputBuffer inbuf = new SessionInputBufferImpl(16, 16, params);
       
        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

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

        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        HttpParams params = new BasicHttpParams();
       
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, params);
        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 SessionInputBufferImpl(1024, 16, params);
        inbuf.fill(channel);
View Full Code Here

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

    }

    public void testComplexReadWriteLine() throws Exception {
        HttpParams params = new BasicHttpParams();
       
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, params);
        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 SessionInputBufferImpl(1024, 16, params);
        inbuf.fill(channel);
View Full Code Here

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

        String s3 = "Like hello and stuff";
       
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setHttpElementCharset(params, "UTF-8");
       
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, 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 SessionInputBufferImpl(16, 16, params);
View Full Code Here

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

    }

    public void testMalformedCharacters() throws Exception {
        HttpParams params = new BasicHttpParams();
        String s1 = constructString(SWISS_GERMAN_HELLO);      
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 16, params);
        try {
            outbuf.writeLine(s1);
            fail("Expected CharacterCodingException");
        } catch (CharacterCodingException expected) {
        }
       
        byte[] tmp = s1.getBytes("ISO-8859-1");       
View Full Code Here

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

    }

    public void testInputMatchesBufferLength() throws Exception {
        HttpParams params = new BasicHttpParams();
        String s1 = "abcde";       
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 5, params);
        outbuf.writeLine(s1);
    }
View Full Code Here

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

   
    public void testBasicCoding() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);
        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
       
        encoder.write(wrap("12345"));
        encoder.write(wrap("678"));
        encoder.write(wrap("90"));
        encoder.complete();
       
        outbuf.flush(channel);
       
        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
Copyright © 2018 www.massapi.com. 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.