Package java.nio

Examples of java.nio.ByteBuffer.compact()


            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


        final byte[] bytes = "hello world".getBytes();

        ByteBuffer writeonlybuffer = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, bytes.length);
        writeonlybuffer.put(bytes);
        writeonlybuffer.compact();
    }

    private File writeToFile2(InputStream archive, String name) throws IOException {
        final File file = File.createTempFile("deploy", "-" + name);
        final FileOutputStream outputStream = new FileOutputStream(file);
View Full Code Here

        try {
            while (decoder.read(inbuf) > 0) {
                inbuf.flip();
                sink.write(inbuf);
                inbuf.compact();
            }

            if (decoder.isCompleted()) {
                if (sink != null) sink.close();
                if (!connStrategy.keepAlive(response, context)) {
View Full Code Here

            if (bytesRead == -1) {
                encoder.complete();
            } else {
                outbuf.flip();
                encoder.write(outbuf);
                outbuf.compact();
            }

            if (encoder.isCompleted()) {
                source.close();
            }
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

                    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

                    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

        try {
            while (decoder.read(inbuf) > 0) {
                inbuf.flip();
                sink.write(inbuf);
                inbuf.compact();
            }

            if (decoder.isCompleted()) {
                sink.close();
            }
View Full Code Here

            if (bytesRead == -1) {
                encoder.complete();
            } else {
                outbuf.flip();
                encoder.write(outbuf);
                outbuf.compact();
            }

            if (encoder.isCompleted()) {
                source.close();
                if (!connStrategy.keepAlive(response, context)) {
View Full Code Here

                                    "sip.network.grizzly.incomplete.tcp.request",
                                    new Object[]{buffer.position()});
                        }
                        initialSize = remaining;
                        if (buffer.hasRemaining()) {
                            buffer.compact();
                        } else {
                            buffer.clear();
                        }

                        // The thread might block when reading more bytes using
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.