Here you can find the source of put(ByteBuffer dst, ByteBuffer src, int transferLimit)
public static ByteBuffer put(ByteBuffer dst, ByteBuffer src, int transferLimit)
//package com.java2s; /* Copyright (c) 2015 University of Massachusetts * /*from ww w . jav a2 s . c o m*/ * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ import java.nio.ByteBuffer; public class Main { /** * Transfer from src to dst without throwing exception if src.remaining() > * dst.remaining() but copying dst.remaining() bytes from src instead. * {@code transferLimit} further limits the number of bytes transferred from * src to dst. */ public static ByteBuffer put(ByteBuffer dst, ByteBuffer src, int transferLimit) { if (src.remaining() <= dst.remaining() && transferLimit >= dst.remaining()) return dst.put(src); int oldLimit = src.limit(); src.limit(src.position() + Math.min(dst.remaining(), transferLimit)); dst.put(src); src.limit(oldLimit); return dst; } public static ByteBuffer put(ByteBuffer dst, ByteBuffer src) { return put(dst, src, dst.remaining()); } }