Package java.nio

Examples of java.nio.ByteBuffer.compact()


            if (i > 0) {
                bytesRead += i;
            }
            tmp.flip();
            dst.put(tmp);
            tmp.compact();
        }

        Assert.assertEquals(16, bytesRead);
        Assert.assertEquals("0123456789abcdef", CodecTestUtils.convert(dst));
        Assert.assertTrue(decoder.isCompleted());
View Full Code Here


            final int i = decoder.read(tmp);
            if (i > 0) {
                bytesRead += i;
                tmp.flip();
                dst.put(tmp);
                tmp.compact();
            }
        }

        Assert.assertEquals(80, bytesRead);
        Assert.assertEquals("12345678901234561234567890123456" +
View Full Code Here

                    expected += 4;
                }
                Assert.assertEquals(testCase.description, expected, i);
                break;
            }
            bb.compact();
        }

        // Configure decoder to replace on an error
        decoder.reset();
        decoder.onMalformedInput(CodingErrorAction.REPLACE);
View Full Code Here

            bb.flip();
            CoderResult cr = decoder.decode(bb, cb, false);
            if (cr.isError()) {
                Assert.fail(testCase.description);
            }
            bb.compact();
        }
        // For incomplete sequences at the end of the input need to tell
        // the decoder the input has ended
        bb.flip();
        CoderResult cr = decoder.decode(bb, cb, true);
View Full Code Here

                    src.flip();
                    if (src.hasRemaining()) {
                        int bytesWritten = encoder.write(src);
                        System.out.println(conn + ": " + bytesWritten + " bytes written");
                    }
                    src.compact();
                   
                    if (src.position() == 0) {
                        if (proxyTask.getClientState() == ProxyTask.REQUEST_BODY_DONE) {
                            encoder.complete();
                        } else {
View Full Code Here

                    src.flip();
                    if (src.hasRemaining()) {
                        int bytesWritten = encoder.write(src);
                        System.out.println(conn + ": " + bytesWritten + " bytes written");
                    }
                    src.compact();

                    if (src.position() == 0) {
                        if (proxyTask.getOriginState() == ProxyTask.RESPONSE_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

                    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

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.