Java ByteBuffer Copy copy(ByteBuffer src, ByteBuffer dst)

Here you can find the source of copy(ByteBuffer src, ByteBuffer dst)

Description

copy

License

Open Source License

Declaration

public static int copy(ByteBuffer src, ByteBuffer dst) 

Method Source Code

//package com.java2s;
/*/* w  w  w  . jav  a2  s .  co m*/
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  Santhosh Kumar T <santhosh.tekuri@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

import java.nio.ByteBuffer;

public class Main {
    public static int copy(ByteBuffer src, ByteBuffer dst) {
        int srcRemaining = src.remaining();
        int dstRemaining = dst.remaining();
        if (srcRemaining <= dstRemaining) {
            dst.put(src);
            return srcRemaining;
        }
        int srcLimit = src.limit();
        src.limit(src.position() + dstRemaining);
        dst.put(src);
        src.limit(srcLimit);
        return dstRemaining;
    }

    public static int copy(ByteBuffer src, ByteBuffer dsts[], int offset, int length) {
        int read = 0;
        while (src.hasRemaining() && length > 0) {
            read += copy(src, dsts[offset]);
            ++offset;
            --length;
        }
        return read;
    }
}

Related

  1. copy(ByteBuffer buffer)
  2. copy(ByteBuffer from, ByteBuffer to)
  3. copy(ByteBuffer origin, int start, int end)
  4. copy(ByteBuffer source)
  5. copy(ByteBuffer source, int byteCount)
  6. copy(ByteBuffer src, ByteBuffer dst, int length)
  7. copy(ByteBuffer src, int srcStartindex, ByteBuffer dest, int destStartIndex, int length)
  8. copy(ByteBuffer src, int startindex, int endindex)
  9. copy(final ByteBuffer from, final ByteBuffer to)