Here you can find the source of fill(ReadableByteChannel in, ByteBuffer buffer)
Parameter | Description |
---|---|
in | the channel to read from |
buffer | the buffer to read into |
Parameter | Description |
---|---|
IOException | if an IO error occurs |
public static ByteBuffer fill(ReadableByteChannel in, ByteBuffer buffer) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; public class Main { /**//from www .java2 s.c o m * Creates a new buffer and fills it with bytes from the * provided channel. The amount of data to read is specified * in the arguments. * * @param in the channel to read from * @param size the number of bytes to read into a new buffer * @return a new buffer containing the bytes read * @throws IOException if an IO error occurs */ public static ByteBuffer fill(ReadableByteChannel in, int size) throws IOException { return fill(in, ByteBuffer.allocate(size)); } /** * Fills the provided buffer it with bytes from the * provided channel. The amount of data to read is * dependant on the available space in the provided * buffer. * * @param in the channel to read from * @param buffer the buffer to read into * @return the provided buffer * @throws IOException if an IO error occurs */ public static ByteBuffer fill(ReadableByteChannel in, ByteBuffer buffer) throws IOException { while (buffer.hasRemaining()) if (in.read(buffer) == -1) throw new BufferUnderflowException(); buffer.flip(); return buffer; } }