2 * Copyright (c) 2013 Contextream, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.lispflowmapping.util;
11 import java.nio.ByteBuffer;
13 public class ByteUtil {
15 public static int getUnsignedByte(byte[] inBuffer, int pos) {
16 return inBuffer[pos] & 0xFF;
19 public static int getUnsignedByte(ByteBuffer inBuffer, int pos) {
20 return inBuffer.get(pos) & 0xFF;
23 public static int getUnsignedShort(byte[] inBuffer, int pos) {
24 return getShort(inBuffer, pos) & 0xFFFF;
27 public static int getUnsignedShort(ByteBuffer inBuffer, int pos) {
28 return inBuffer.getShort(pos) & 0xFFFF;
31 public static short getShort(byte[] inBuffer, int pos) {
32 return ByteBuffer.wrap(inBuffer, pos, 2).getShort();
35 public static int getInt(byte[] inBuffer, int pos) {
36 return ByteBuffer.wrap(inBuffer, pos, 4).getInt();
39 public static long getLong(byte[] inBuffer, int pos) {
40 return ByteBuffer.wrap(inBuffer, pos, 8).getLong();
43 public static boolean extractBit(byte byteValue, int bitMask) {
44 return (byteValue & bitMask) == bitMask;
47 public static byte boolToBit(boolean flag, int bit) {
48 return (byte) (flag ? bit : 0x00);