Package java.nio

Examples of java.nio.ByteBuffer.compact()


                return false;
            }
           
            inputBuffer.flip();    // Prepare for reading
            boolean status = clientHandler.handleIncomingData();
            inputBuffer.compact(); // Restore pointers
           
            return status;
        }
        catch (IOException e)
        {
View Full Code Here


            catch (IOException e)
            {
                log.error("["+clientHandler.getId()+"] Write failed : "+e.getMessage());
                writeAmount = -1;
            }
            outputBuffer.compact(); // Restore pointers

            return (writeAmount > 0);
        }
        catch (Exception e)
        {
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

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

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

    private File writeToFile2(final InputStream archive, final String name) throws IOException {
        File file;
        try {
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

        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

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.