Get the array from a read-only {@link ByteBuffer} similar to {@link ByteBuffer#array()}.

@param buffer that wraps the underlying array.
@return the underlying array.
491709
public static byte[] array(final ByteBuffer buffer)
    {
        if (buffer.isDirect())
        {
            throw new IllegalArgumentException("buffer must wrap an array");
        }

        return (byte[])UNSAFE.getObject(buffer, BYTE_BUFFER_HB_FIELD_OFFSET);
    }
488654
private static byte[] bufferToArray(final ByteBuffer body) {
    if (body.position() > 0) {
      body.flip();
    }
    final int length = body.limit();
    final byte[] bytes = new byte[length];
    System.arraycopy(body.array(), 0, bytes, 0, length);
    return bytes;
  }
551288
public static ByteBuf wrappedBuffer(ByteBuffer buffer) {
        if (!buffer.hasRemaining()) {
            return EMPTY_BUFFER;
        }
        if (!buffer.isDirect() && buffer.hasArray()) {
            return wrappedBuffer(
                    buffer.array(),
                    buffer.arrayOffset() + buffer.position(),
                    buffer.remaining()).order(buffer.order());
        } else if (PlatformDependent.hasUnsafe()) {
            if (buffer.isReadOnly()) {
                if (buffer.isDirect()) {
                    return new ReadOnlyUnsafeDirectByteBuf(ALLOC, buffer);
                } else {
                    return new ReadOnlyByteBufferBuf(ALLOC, buffer);
                }
            } else {
                return new UnpooledUnsafeDirectByteBuf(ALLOC, buffer, buffer.remaining());
            }
        } else {
            if (buffer.isReadOnly()) {
                return new ReadOnlyByteBufferBuf(ALLOC, buffer);
            }  else {
                return new UnpooledDirectByteBuf(ALLOC, buffer, buffer.remaining());
            }
        }
    }
754340
public static IntArray getInstance(byte[] buffer, int offset, int length)
    {
        return getInstance(buffer, offset, length, 8, ByteOrder.BIG_ENDIAN);
    }
567791
public static byte[] toBytes(ByteBuffer bb) {
    int length = bb.limit();
    byte [] result = new byte[length];
    System.arraycopy(bb.array(), bb.arrayOffset(), result, 0, length);
    return result;
  }
1350167
public static byte[] asArray(ByteBuffer byteBuffer) {
        ByteBuffer bb = ByteBufferUtil.clone(byteBuffer);
        byte[] bytes = new byte[bb.remaining()];
        bb.get(bytes);
        return bytes;
    }
37199
@Override
    public short[] read(ScanBuffer buffer) {
        int length = getLength(buffer);
        if (length<0) return null;
        return buffer.getShorts(length);
    }
1097042
public static Slice wrappedBuffer(ByteBuffer buffer)
    {
        if (buffer.isDirect()) {
            long address = bufferAddress(buffer);
            return new Slice(null, address + buffer.position(), buffer.remaining(), buffer.capacity(), buffer);
        }

        if (buffer.hasArray()) {
            return new Slice(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
        }

        throw new IllegalArgumentException("cannot wrap " + buffer.getClass().getName());
    }
733070
public ObjectManagerByteArrayOutputStream[] getBuffers(ObjectManagerByteArrayOutputStream byteArrayOutputStream)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "getBuffers",
                        new Object[] { byteArrayOutputStream });

        ObjectManagerByteArrayOutputStream[] buffers = new ObjectManagerByteArrayOutputStream[1];

        //  Create the buffer to contain the header for this log record.
        byteArrayOutputStream.reset();
        buffers[0] = byteArrayOutputStream;

        buffers[0].writeInt(LogRecord.TYPE_PREPARE);
        logicalUnitOfWork.writeSerializedBytes(buffers[0]);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "getBuffers",
                       buffers);
        return buffers;
    }
928326
public static Packet build(IoBuffer buffer) {
        if (buffer.hasArray()) {
            return new Packet(buffer.array());
        }
        byte[] buf = new byte[buffer.remaining()];
        buffer.get(buf);
        return new Packet(buf);
    }
696183
public synchronized byte[] getBuffer() {
        byte[] dest = new byte[buf.length];
        System.arraycopy(buf, 0, dest, 0, dest.length);
        return dest;
    }
605164
@Override
    public byte[] getBuffer () {
        synchronized ( this.cache ) {
            byte[] buf;

            if ( this.freeBuffers > 0 ) {
                for ( int i = 0; i < this.cache.length; i++ ) {
                    if ( this.cache[ i ] != null ) {
                        buf = (byte[]) this.cache[ i ];
                        this.cache[ i ] = null;
                        this.freeBuffers--;
                        return buf;
                    }
                }
            }
            return new byte[this.bufferSize];
        }
    }
1075681
public static byte[] toArray(ByteBuffer bytebuffer) {
		if (false == bytebuffer.hasArray()) {
			int oldPosition = bytebuffer.position();
			bytebuffer.position(0);
			int size = bytebuffer.limit();
			byte[] buffers = new byte[size];
			bytebuffer.get(buffers);
			bytebuffer.position(oldPosition);
			return buffers;
		} else {
			return Arrays.copyOfRange(bytebuffer.array(), bytebuffer.position(), bytebuffer.limit());
		}
	}
1010362
public ByteBuffer getBuffer() {
        assert(isDirect == false);
        assert(buffer.b().hasArray());
        assert(!buffer.b().isDirect());
        buffer.b().flip();
        return buffer.b().asReadOnlyBuffer();
    }
596203
public int read(final byte[] buffer) throws IOException {
    // Note that GWT will throw a JavascriptException rather than a NullPointerException if we
    // skip this check and the buffer array is null. This way we ensure that this implementation
    // behaves in the same way as the classes that are emulated.
    if (buffer == null) {
      throw new NullPointerException();
    }
    return this.read(buffer, 0, buffer.length);
  }
154743
@Override
    public byte[] read(ScanBuffer buffer) {
        int length = getLength(buffer);
        if (length<0) return null;
        return buffer.getBytes(length);
    }
194320
public static byte[] readBytes(ByteBuffer buffer, int offset, int size) {
        final byte[] dest = new byte[size];
        buffer.get(dest, offset, size);
        return dest;
    }