transfer one ByteBuffer to another ByteBuffer - Java java.nio

Java examples for java.nio:ByteBuffer

Description

transfer one ByteBuffer to another ByteBuffer

Demo Code


//package com.java2s;

import java.nio.ByteBuffer;

public class Main {
    public static int transfer(ByteBuffer src, ByteBuffer dst) {
        int numBytes = Math.min(src.remaining(), dst.remaining());
        if (numBytes > 0) {
            int oldLimit = src.limit();
            src.limit(src.position() + numBytes);
            dst.put(src);/*from  ww w.j  ava  2s .  co m*/
            src.limit(oldLimit);
        }
        return numBytes;
    }
}

Related Tutorials