Package java.nio.channels

Examples of java.nio.channels.WritableByteChannel


       
        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


        //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);
View Full Code Here

        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);
View Full Code Here

            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);       
View Full Code Here

            ConnState connState = (ConnState) context.getAttribute(
                    CONN_STATE);
            try {

                WritableByteChannel channel = connState.getInputChannel();
                long transferred;

                // Test if the decoder is capable of direct transfer to file
                if (this.useFileChannels &&
                        decoder instanceof FileContentDecoder &&
                        channel instanceof FileChannel) {
                    long pos = connState.getInputCount();
                    transferred = ((FileContentDecoder) decoder).transfer(
                            (FileChannel) channel, pos, Integer.MAX_VALUE);
                } else {
                    ByteBuffer buf = connState.getInbuf();
                    decoder.read(buf);
                    buf.flip();
                    transferred = channel.write(buf);
                    buf.compact();
                }
                connState.incrementInputCount(transferred);
               
                if (decoder.isCompleted()) {
                    // Request entity has been fully received
                    channel.close();
                    doService(conn, connState);
                }
               
            } catch (HttpException ex) {
                shutdownConnection(conn);
View Full Code Here

        return Channels.newChannel(baos);
    }
   
    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);
       
View Full Code Here

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

    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();
        ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
       
View Full Code Here

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

    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();
        ChunkEncoder encoder = new ChunkEncoder(channel, outbuf, metrics);
       
View Full Code Here

        }
    }

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

        try {
            new ChunkEncoder(null, null, null);
View Full Code Here

                //configure output channel
                sc = attachment.getChannel();
                sc.setSendFile(true);
                //ssl channel is slightly different
                WritableByteChannel wc =(WritableByteChannel) ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel());

                //we still have data in the buffer
                if (sc.getOutboundRemaining()>0) {
                    if (sc.flushOutbound()) {
                        attachment.access();
View Full Code Here

TOP

Related Classes of java.nio.channels.WritableByteChannel

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.