Package java.nio

Examples of java.nio.ByteBuffer.compact()


            int i = decoder.read(tmp);
            if (i > 0) {
                bytesRead += i;
                tmp.flip();
                dst.put(tmp);
                tmp.compact();
            }
        }
       
        assertEquals(80, bytesRead);
        assertEquals("12345678901234561234567890123456" +
View Full Code Here


                    ByteBuffer src = proxyTask.getOutBuffer();
                    src.flip();
                    int bytesWritten = encoder.write(src);
                    System.out.println(conn + " [client<-proxy] " + bytesWritten + " bytes written");
                    System.out.println(conn + " [client<-proxy] " + encoder);
                    src.compact();

                    if (src.position() == 0) {

                        if (proxyTask.getOriginState() == ConnState.RESPONSE_BODY_DONE) {
                            encoder.complete();
View Full Code Here

                    ByteBuffer src = proxyTask.getInBuffer();
                    src.flip();
                    int bytesWritten = encoder.write(src);
                    System.out.println(conn + " [proxy->origin] " + bytesWritten + " bytes written");
                    System.out.println(conn + " [proxy->origin] " + encoder);
                    src.compact();
                   
                    if (src.position() == 0) {
                        if (proxyTask.getClientState() == ConnState.REQUEST_BODY_DONE) {
                            encoder.complete();
                        } else {
View Full Code Here

                    ByteBuffer src = proxyTask.getOutBuffer();
                    src.flip();
                    int bytesWritten = encoder.write(src);
                    System.out.println(conn + " [client<-proxy] " + bytesWritten + " bytes written");
                    System.out.println(conn + " [client<-proxy] " + encoder);
                    src.compact();

                    if (src.position() == 0) {

                        if (proxyTask.getOriginState() == ConnState.RESPONSE_BODY_DONE) {
                            encoder.complete();
View Full Code Here

                    ByteBuffer src = proxyTask.getInBuffer();
                    src.flip();
                    int bytesWritten = encoder.write(src);
                    System.out.println(conn + " [proxy->origin] " + bytesWritten + " bytes written");
                    System.out.println(conn + " [proxy->origin] " + encoder);
                    src.compact();
                   
                    if (src.position() == 0) {
                        if (proxyTask.getClientState() == ConnState.REQUEST_BODY_DONE) {
                            encoder.complete();
                        } else {
View Full Code Here

            if (i > 0) {
                bytesRead += i;
            }
            tmp.flip();
            dst.put(tmp);
            tmp.compact();
        }
       
        assertEquals(16, bytesRead);
        assertEquals("0123456789abcdef", convert(dst));
        assertTrue(decoder.isCompleted());
View Full Code Here

                this.httpExchange.setOriginIOControl(ioctrl);
                // Send data to the origin server
                ByteBuffer buf = this.httpExchange.getInBuffer();
                buf.flip();
                int n = encoder.write(buf);
                buf.compact();
                System.out.println("[proxy->origin] " + this.httpExchange.getId() + " " + n + " bytes written");
                // If there is space in the buffer and the message has not been
                // transferred, make sure the client is sending more data
                if (buf.hasRemaining() && !this.httpExchange.isRequestReceived()) {
                    if (this.httpExchange.getClientIOControl() != null) {
View Full Code Here

                this.httpExchange.setClientIOControl(ioctrl);
                // Send data to the client
                ByteBuffer buf = this.httpExchange.getOutBuffer();
                buf.flip();
                int n = encoder.write(buf);
                buf.compact();
                System.out.println("[client<-proxy] " + this.httpExchange.getId() + " " + n + " bytes written");
                // If there is space in the buffer and the message has not been
                // transferred, make sure the origin is sending more data
                if (buf.hasRemaining() && !this.httpExchange.isResponseReceived()) {
                    if (this.httpExchange.getOriginIOControl() != null) {
View Full Code Here

        final ByteBuffer outEncryptedBuf = this.outEncrypted.acquire();

        // Perform operation
        outEncryptedBuf.flip();
        final int bytesWritten = this.session.channel().write(outEncryptedBuf);
        outEncryptedBuf.compact();

        // Release if empty
        if (outEncryptedBuf.position() == 0) {
            this.outEncrypted.release();
        }
View Full Code Here

            inPlainBuf.flip();
            final int n = Math.min(inPlainBuf.remaining(), dst.remaining());
            for (int i = 0; i < n; i++) {
                dst.put(inPlainBuf.get());
            }
            inPlainBuf.compact();

            // Release if empty
            if (inPlainBuf.position() == 0) {
                this.inPlain.release();
                inPlainBuf = null;
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.