Here you can find the source of putWhatFits(ByteBuffer dest, ByteBuffer src)
src
as will fit in dest
.
Parameter | Description |
---|---|
dest | the destination buffer. |
src | the source buffer. |
public static void putWhatFits(ByteBuffer dest, ByteBuffer src)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { /**// w w w .ja v a 2 s. c om * Puts as much of <code>src</code> as will fit in <code>dest</code>. * * The minimum of (<code>dest.remaining()</code> and <code>src.remaining()</code>) is copied from src * to dest, and their respective positions moved by that much. * * @param dest the destination buffer. * @param src the source buffer. */ public static void putWhatFits(ByteBuffer dest, ByteBuffer src) { final int toPut = Math.min(dest.remaining(), src.remaining()); if (toPut == src.remaining()) { dest.put(src); } else { if (toPut != 0) { final ByteBuffer slice = src.slice(); slice.limit(toPut); src.position(src.position() + toPut); dest.put(slice); } } } }