Java ByteBuffer to Byte Array getBytes(ByteBuffer bb)

Here you can find the source of getBytes(ByteBuffer bb)

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(ByteBuffer bb) 

Method Source Code


//package com.java2s;
/*//from  www  .j av  a 2s.c o  m
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2007, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program 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 General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

import java.nio.ByteBuffer;

public class Main {
    public static byte[] getBytes(ByteBuffer bb) {
        if (bb.hasArray() && bb.arrayOffset() == 0 && bb.position() == 0) {
            byte[] b = bb.array();
            if (b.length == bb.limit())
                return b;
        }
        byte[] b = new byte[bb.limit() - bb.position()];
        bb.duplicate().get(b);
        return b;
    }
}

Related

  1. getByteArray(ByteBuffer byteBuffer)
  2. getByteArray(ByteBuffer byteBuffer)
  3. getByteArray(final ByteBuffer buff)
  4. getByteArrayFromBuffer(ByteBuffer byteBuf)
  5. getByteArrayFromByteBuffer(ByteBuffer content)
  6. getBytes(ByteBuffer buf)
  7. getBytes(ByteBuffer buf)
  8. getBytes(ByteBuffer buf, byte[] arr)
  9. getBytes(ByteBuffer buf, int length)