Java ByteBuffer Write writeByteArray(ByteBuffer logBuf, byte[] b)

Here you can find the source of writeByteArray(ByteBuffer logBuf, byte[] b)

Description

Write a byte array into the log.

License

Open Source License

Declaration

public static void writeByteArray(ByteBuffer logBuf, byte[] b) 

Method Source Code


//package com.java2s;
/*-//from   w  w w  .j a  v a  2 s. c  om
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002,2007 Oracle.  All rights reserved.
 *
 * $Id: LogUtils.java,v 1.50.2.1 2007/02/01 14:49:47 cwl Exp $
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Write a byte array into the log. The size is stored first as an integer.
     */
    public static void writeByteArray(ByteBuffer logBuf, byte[] b) {

        /* Write the length. */
        writeInt(logBuf, b.length);

        /* Add the data itself. */
        logBuf.put(b); // data
    }

    /**
     * Write an int into the log.
     */
    public static void writeInt(ByteBuffer logBuf, int i) {
        byte b = (byte) ((i >> 0) & 0xff);
        logBuf.put(b);
        b = (byte) ((i >> 8) & 0xff);
        logBuf.put(b);
        b = (byte) ((i >> 16) & 0xff);
        logBuf.put(b);
        b = (byte) ((i >> 24) & 0xff);
        logBuf.put(b);
    }
}

Related

  1. writeBuffer(WritableByteChannel chan, ByteBuffer buf)
  2. writeByte(ByteBuffer dest, int off, int i)
  3. writeByteArray(byte[] array, ByteBuffer out)
  4. writeByteArray(byte[] data, ByteBuffer buffer)
  5. writeByteArray(ByteBuffer byteBuffer, byte[] bytes)
  6. writeByteBuffer(ByteBuffer bbuf, String filename)
  7. writeByteBuffer(RandomAccessFile file, ByteBuffer buffer)
  8. writeByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
  9. writeBytesNoLength(ByteBuffer logBuf, byte[] b)