Java ByteBuffer Copy copy(ByteBuffer buffer)

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

Description

Copy buffer to byte array

License

Open Source License

Parameter

Parameter Description
buffer a parameter

Declaration

private static final byte[] copy(ByteBuffer buffer) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    /**//  ww w .  ja  v  a  2 s .co  m
     * Copy binary
     * @param bytes
     * @return
     */
    private static final byte[] copy(byte[] bytes) {
        byte[] copy = new byte[bytes.length];
        System.arraycopy(bytes, 0, copy, 0, bytes.length);
        return copy;
    }

    /**
     * Copy buffer to byte array
     * @param buffer
     * @return
     */
    private static final byte[] copy(ByteBuffer buffer) {
        buffer.mark();
        byte[] bytes = new byte[buffer.limit()];
        buffer.get(bytes);
        buffer.reset();
        return bytes;
    }
}

Related

  1. copy(ByteBuffer bb, boolean forceDirect)
  2. copy(ByteBuffer buf)
  3. copy(ByteBuffer buffer)
  4. copy(ByteBuffer buffer)
  5. copy(ByteBuffer from, ByteBuffer to)
  6. copy(ByteBuffer origin, int start, int end)
  7. copy(ByteBuffer source)