Java ByteBuffer Endian extractShort(ByteBuffer buffer, boolean bigEndian)

Here you can find the source of extractShort(ByteBuffer buffer, boolean bigEndian)

Description

extract Short

License

Creative Commons License

Parameter

Parameter Description
buffer a parameter

Declaration

private static byte[] extractShort(ByteBuffer buffer, boolean bigEndian) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    /**/*from ww  w  .  ja  v a  2 s  .  co m*/
     * @param buffer
     * @return
     */
    private static byte[] extractShort(ByteBuffer buffer, boolean bigEndian) {
        byte b1, b2;
        byte[] result = new byte[2];
        b1 = buffer.get();
        b2 = buffer.get();
        if (bigEndian) {
            result[0] = b1;
            result[1] = b2;
        } else {
            result[0] = b2;
            result[1] = b1;
        }
        return result;
    }
}

Related

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