Java ByteBuffer Write writeFully(ByteBuffer buffer, WritableByteChannel channel)

Here you can find the source of writeFully(ByteBuffer buffer, WritableByteChannel channel)

Description

Writes the entire remaining contents of the buffer to the channel.

License

Open Source License

Parameter

Parameter Description
buffer the data to be written
channel the channel to which we want to write data

Exception

Parameter Description
IOException if there is a problem writing to the channel

Declaration

public static void writeFully(ByteBuffer buffer, WritableByteChannel channel) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

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

public class Main {
    /**/*  w ww .  ja v  a2s  . com*/
     * Writes the entire remaining contents of the buffer to the channel. May complete in one operation, but the
     * documentation is vague, so this keeps going until we are sure.
     *
     * @param buffer the data to be written
     * @param channel the channel to which we want to write data
     *
     * @throws IOException if there is a problem writing to the channel
     */
    public static void writeFully(ByteBuffer buffer, WritableByteChannel channel) throws IOException {
        while (buffer.hasRemaining()) {
            channel.write(buffer);
        }
    }
}

Related

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