Java ByteBuffer Copy copy(ByteBuffer buf)

Here you can find the source of copy(ByteBuffer buf)

Description

copy

License

Open Source License

Declaration

static ByteBuffer copy(ByteBuffer buf) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    static ByteBuffer copy(ByteBuffer buf) {
        ByteBuffer ret;/*  w  ww  . j  a  va 2s . c  o  m*/

        if (buf.isDirect()) {
            ret = buf.allocateDirect(buf.remaining());
        } else {
            ret = buf.allocate(buf.remaining());
        }

        ret.put(buf.duplicate());
        ret.clear();

        return ret;
    }
}

Related

  1. copy(ByteBuffer bb, boolean forceDirect)
  2. copy(ByteBuffer buffer)
  3. copy(ByteBuffer buffer)
  4. copy(ByteBuffer buffer)
  5. copy(ByteBuffer from, ByteBuffer to)