Here you can find the source of getBytes(ByteBuffer bb)
public static byte[] getBytes(ByteBuffer bb)
//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; } }