Here you can find the source of put(ByteBuffer from, ByteBuffer to)
Parameter | Description |
---|---|
from | Buffer to take bytes from in flush mode |
to | Buffer to put bytes to in fill mode. |
public static int put(ByteBuffer from, ByteBuffer to)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.nio.ByteBuffer; public class Main { /**/* w ww.j a v a 2 s. c om*/ * Put data from one buffer into another, avoiding over/under flows * @param from Buffer to take bytes from in flush mode * @param to Buffer to put bytes to in fill mode. * @return number of bytes moved */ public static int put(ByteBuffer from, ByteBuffer to) { int put; int remaining = from.remaining(); if (remaining > 0) { if (remaining <= to.remaining()) { to.put(from); put = remaining; from.position(from.limit()); } else if (from.hasArray()) { put = to.remaining(); to.put(from.array(), from.arrayOffset() + from.position(), put); from.position(from.position() + put); } else { put = to.remaining(); ByteBuffer slice = from.slice(); slice.limit(put); to.put(slice); from.position(from.position() + put); } } else put = 0; return put; } }