Here you can find the source of transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos)
public static void transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { /**// ww w . j av a2s .com * Copy as many byte from source to target, until either source has no more data, target cannot take more or * the trg.position() is equals to limit value. */ public static void transferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos) { int cpySz = Math.min(src.remaining(), Math.min(trgPos - trg.position(), trg.remaining())); if (cpySz <= 0) { return; } int oldLimit = src.limit(); src.limit(src.position() + cpySz); trg.put(src); src.limit(oldLimit); } }