ignore transiant files in git
[lispflowmapping.git] / mappingservice / api / src / main / java / org / opendaylight / lispflowmapping / util / ByteUtil.java
1 /*
2  * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.lispflowmapping.util;
10
11 import java.nio.ByteBuffer;
12
13 public class ByteUtil {
14
15     public static int getUnsignedByte(byte[] inBuffer, int pos) {
16         return inBuffer[pos] & 0xFF;
17     }
18
19     public static int getUnsignedByte(ByteBuffer inBuffer, int pos) {
20         return inBuffer.get(pos) & 0xFF;
21     }
22
23     public static int getUnsignedShort(byte[] inBuffer, int pos) {
24         return getShort(inBuffer, pos) & 0xFFFF;
25     }
26
27     public static int getUnsignedShort(ByteBuffer inBuffer, int pos) {
28         return inBuffer.getShort(pos) & 0xFFFF;
29     }
30
31     public static short getShort(byte[] inBuffer, int pos) {
32         return ByteBuffer.wrap(inBuffer, pos, 2).getShort();
33     }
34
35     public static int getInt(byte[] inBuffer, int pos) {
36         return ByteBuffer.wrap(inBuffer, pos, 4).getInt();
37     }
38
39     public static long getLong(byte[] inBuffer, int pos) {
40         return ByteBuffer.wrap(inBuffer, pos, 8).getLong();
41     }
42
43     public static boolean extractBit(byte byteValue, int bitMask) {
44         return (byteValue & bitMask) == bitMask;
45     }
46
47     public static byte boolToBit(boolean flag, int bit) {
48         return (byte) (flag ? bit : 0x00);
49     }
50 }