Java ByteBuffer Write writeFully(ByteBuffer buf, WritableByteChannel out)

Here you can find the source of writeFully(ByteBuffer buf, WritableByteChannel out)

Description

if we were to register for OP_WRITE and send the remaining data on readyOps for this channel we have to either block the caller thread or queue the message buffers that may arrive while waiting for OP_WRITE.

License

LGPL

Declaration

public static void writeFully(ByteBuffer buf, WritableByteChannel out) throws Exception 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;

public class Main {
    /**//  w ww . ja  v a  2  s.co  m
    * if we were to register for OP_WRITE and send the remaining data on
    * readyOps for this channel we have to either block the caller thread or
    * queue the message buffers that may arrive while waiting for OP_WRITE.
    * Instead of the above approach this method will continuously write to the
    * channel until the buffer sent fully.
    */
    public static void writeFully(ByteBuffer buf, WritableByteChannel out) throws Exception {
        int written = 0;
        int toWrite = buf.limit();
        while (written < toWrite) {
            written += out.write(buf);
        }
    }
}

Related

  1. writeFile(File file, ByteBuffer buffer)
  2. writeFileFragment(FileChannel fc, long pos, ByteBuffer fragment)
  3. writeFloat(ByteBuffer buffer, float f)
  4. writeFromBuffer(SocketChannel channel, ByteBuffer buf, int sleepMsecs)
  5. writeFully(@Nonnull final FileChannel dst, @Nonnull final ByteBuffer src, @Nonnegative final long position)
  6. writeFully(ByteBuffer buffer, WritableByteChannel channel)
  7. writeFully(FileChannel channel, ByteBuffer fileInfosBuffer)
  8. writeFully(FileChannel channel, ByteBuffer src)
  9. writeFully(FileChannel channel, long offset, ByteBuffer buf)