Java ByteBuffer Put putByteArray(ByteBuffer byteBuffer, byte[] array)

Here you can find the source of putByteArray(ByteBuffer byteBuffer, byte[] array)

Description

put Byte Array

License

Open Source License

Declaration

public static void putByteArray(ByteBuffer byteBuffer, byte[] array) 

Method Source Code

//package com.java2s;
/*/*  www  .j a  v a  2  s  .  c  o m*/
 * Copyright (c) 2007, 2011-2013 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */

import java.nio.ByteBuffer;

public class Main {
    public static void putByteArray(ByteBuffer byteBuffer, byte[] array) {
        short length = array == null ? 0 : (short) array.length;
        byteBuffer.putShort(length); // BYTE_ARRAY_PREFIX
        if (length != 0) {
            byteBuffer.put(array);
        }
    }
}

Related

  1. put3ByteInt(ByteBuffer buffer, int val)
  2. putAscii(ByteBuffer bytes, String value)
  3. putAsMuchAsPossible(ByteBuffer dest, ByteBuffer src)
  4. putBoolean(ByteBuffer bb, boolean value)
  5. putByte(ByteBuffer byteBuffer, int value)
  6. putByteAsString(ByteBuffer buffer, byte value)
  7. putByteBuffer(ByteBuffer source, ByteBuffer target)
  8. putBytesUnescaped(ByteBuffer buffer, byte[] data)
  9. putCharSequence(ByteBuffer buf, Charset charset, CharSequence value)