Java ByteBuffer to Byte Array readBytesNoLength(ByteBuffer logBuf, int size)

Here you can find the source of readBytesNoLength(ByteBuffer logBuf, int size)

Description

Read a byte array from the log.

License

Open Source License

Declaration

public static byte[] readBytesNoLength(ByteBuffer logBuf, int size) 

Method Source Code


//package com.java2s;
/*-//from   ww w .j a v  a 2s  .co  m
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2010 Oracle.  All rights reserved.
 *
 */

import java.nio.ByteBuffer;

public class Main {
    private static final boolean DEBUG = false;
    public static final byte[] ZERO_LENGTH_BYTE_ARRAY = new byte[0];

    /**
     * Read a byte array from the log.  The size is not stored.
     */
    public static byte[] readBytesNoLength(ByteBuffer logBuf, int size) {
        if (DEBUG) {
            System.out.println("pos = " + logBuf.position() + " byteArray is " + size + " on read");
        }

        if (size == 0) {
            return ZERO_LENGTH_BYTE_ARRAY;
        }

        byte[] b = new byte[size];
        logBuf.get(b); // read it out
        return b;
    }
}

Related

  1. getBytesFromByteBuffer(ByteBuffer byteBuffer)
  2. getBytesFromByteBuffer(Object obj)
  3. readBytes(byte[] dest, int offset, int length, ByteBuffer buffer)
  4. readBytes(SocketChannel socketChannel, ByteBuffer byteBuffer, int length)
  5. readBytesFromByteBuffer(ByteBuffer byteBuffer)
  6. readBytesWithShortLength(ByteBuffer bb)
  7. toArray(ByteBuffer buffer)
  8. toArray(ByteBuffer buffer)
  9. toArray(ByteBuffer buffer)