Java ByteBuffer Endian extractInt(ByteBuffer header_buf, boolean bigEndian)

Here you can find the source of extractInt(ByteBuffer header_buf, boolean bigEndian)

Description

extract Int

License

Creative Commons License

Parameter

Parameter Description
header_buf a parameter
bigEndian a parameter

Declaration

public static byte[] extractInt(ByteBuffer header_buf, boolean bigEndian) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

import java.nio.ByteBuffer;

public class Main {
    /**// www  .  j av a  2 s .  c o m
     * 
     * @param header_buf
     * @param bigEndian
     * @return
     */
    public static byte[] extractInt(ByteBuffer header_buf, boolean bigEndian) {
        byte b1, b2, b3, b4;
        b1 = header_buf.get();
        b2 = header_buf.get();
        b3 = header_buf.get();
        b4 = header_buf.get();
        byte[] result = new byte[4];
        if (bigEndian) {
            result[0] = b1;
            result[1] = b2;
            result[2] = b3;
            result[3] = b4;
        } else {
            result[0] = b4;
            result[1] = b3;
            result[2] = b2;
            result[3] = b1;
        }

        return result;
    }
}

Related

  1. assertByteOrderLittleEndian(ByteBuffer buffer)
  2. convertLittleEndianLong(ByteBuffer buff, int size)
  3. decodeLittleEndianFixedWidthLong(ByteBuffer buffer)
  4. decodeLittleEndianVarInt(ByteBuffer buffer)
  5. extractShort(ByteBuffer buffer, boolean bigEndian)
  6. inLittleEndianOrder(ByteBuffer buf)
  7. swapEndian16(ByteBuffer buf)