Here you can find the source of write(WritableByteChannel out, ByteBuffer buffer)
public static int write(WritableByteChannel out, ByteBuffer buffer) throws IOException
//package com.java2s; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; public class Main { public static int write(WritableByteChannel out, ByteBuffer buffer) throws IOException { int bytesWritten = 0; while (buffer.hasRemaining()) { bytesWritten += out.write(buffer); }/*from ww w. j a v a 2 s . c o m*/ return bytesWritten; } }