Java examples for java.nio.channels:ReadableByteChannel
fill Buffer from ReadableByteChannel
//package com.java2s; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; public class Main { public static boolean fillBuffer(ReadableByteChannel channel, ByteBuffer buf, boolean clear) throws IOException { if (clear) buf.clear();//from www . j a va 2s . com while (true) { int cnt = channel.read(buf); if (cnt < 0) return false; if (buf.position() == buf.capacity()) break;// fill to capacity } return true; } }