* Returns the first byte from the byte array
* @return byte value
*/
- public static byte getByte(byte[] data) {
+ public static byte getByte(final byte[] data) {
if ((data.length * NetUtils.NumBitsInAByte) > Byte.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
* Size of byte array is restricted to Short.SIZE
* @return short value
*/
- public static short getShort(byte[] data) {
+ public static short getShort(final byte[] data) {
if (data.length > Short.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
* Size of byte array is restricted to Integer.SIZE
* @return int - the integer value of byte array
*/
- public static int getInt(byte[] data) {
+ public static int getInt(final byte[] data) {
if (data.length > Integer.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
* Size of byte array is restricted to Long.SIZE
* @return long - the integer value of byte array
*/
- public static long getLong(byte[] data) {
+ public static long getLong(final byte[] data) {
if (data.length > Long.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (Exception e) {
+ } catch (final Exception e) {
logger.error("", e);
}
}
* Size of numBits is restricted to Short.SIZE
* @return short - the short value of byte array
*/
- public static short getShort(byte[] data, int numBits) {
+ public static short getShort(final byte[] data, final int numBits) {
if (numBits > Short.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
byte[] bits = null;
try {
bits = BitBufferHelper.getBits(data, startOffset, numBits);
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
return (short) toNumber(bits, numBits);
* Size of numBits is restricted to Integer.SIZE
* @return int - the integer value of byte array
*/
- public static int getInt(byte[] data, int numBits) {
+ public static int getInt(final byte[] data, final int numBits) {
if (numBits > Integer.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
byte[] bits = null;
try {
bits = BitBufferHelper.getBits(data, startOffset, numBits);
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
return (int) toNumber(bits, numBits);
* Size of numBits is restricted to Long.SIZE
* @return long - the integer value of byte array
*/
- public static long getLong(byte[] data, int numBits) {
+ public static long getLong(final byte[] data, final int numBits) {
if (numBits > Long.SIZE) {
try {
throw new BufferException(
"Container is too small for the number of requested bits");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
try {
throw new BufferException(
"Trying to read more bits than contained in the data buffer");
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
}
byte[] bits = null;
try {
bits = BitBufferHelper.getBits(data, startOffset, numBits);
- } catch (BufferException e) {
+ } catch (final BufferException e) {
logger.error("", e);
}
return toNumber(bits, numBits);
* when the startOffset and numBits parameters are not congruent
* with the data buffer size
*/
- public static byte[] getBits(byte[] data, int startOffset, int numBits)
+ public static byte[] getBits(final byte[] data, final int startOffset, final int numBits)
throws BufferException {
int startByteOffset = 0;
* when the input, startOffset and numBits are not congruent
* with the data buffer size
*/
- public static void setByte(byte[] data, byte input, int startOffset,
- int numBits) throws BufferException {
+ public static void setByte(final byte[] data, final byte input, final int startOffset,
+ final int numBits) throws BufferException {
byte[] inputByteArray = new byte[1];
Arrays.fill(inputByteArray, 0, 1, input);
setBytes(data, inputByteArray, startOffset, numBits);
* when the startOffset and numBits parameters are not congruent
* with data and input buffers' size
*/
- public static void setBytes(byte[] data, byte[] input, int startOffset,
- int numBits) throws BufferException {
+ public static void setBytes(final byte[] data, final byte[] input, final int startOffset,
+ final int numBits) throws BufferException {
checkExceptions(data, startOffset, numBits);
insertBits(data, input, startOffset, numBits);
}
/**
* Returns numBits 1's in the MSB position
*/
- public static int getMSBMask(int numBits) {
+ public static int getMSBMask(final int numBits) {
int mask = 0;
for (int i = 0; i < numBits; i++) {
mask = mask | (1 << (7 - i));
/**
* Returns numBits 1's in the LSB position
*/
- public static int getLSBMask(int numBits) {
+ public static int getLSBMask(final int numBits) {
int mask = 0;
for (int i = 0; i < numBits; i++) {
mask = mask | (1 << i);
*
* @return long - numerical value of byte array passed
*/
- static public long toNumber(byte[] array) {
+ static public long toNumber(final byte[] array) {
long ret = 0;
long length = array.length;
int value = 0;
*
* @return long - numerical value of byte array passed
*/
- static public long toNumber(byte[] array, int numBits) {
+ static public long toNumber(final byte[] array, final int numBits) {
int length = numBits / NetUtils.NumBitsInAByte;
int bitsRest = numBits % NetUtils.NumBitsInAByte;
int startOffset = array.length - length;
* aligned form example: input = 5000 [1001110001000] bytes = 19, -120
* [00010011] [10001000]
*/
- public static byte[] toByteArray(Number input) {
+ public static byte[] toByteArray(final Number input) {
Class<? extends Number> dataType = input.getClass();
short size = 0;
long longValue = input.longValue();
* @return byte[]
*
*/
- public static byte[] toByteArray(Number input, int numBits) {
+ public static byte[] toByteArray(final Number input, final int numBits) {
Class<? extends Number> dataType = input.getClass();
short size = 0;
long longValue = input.longValue();
* @param numBits - number of bits to be left aligned
* @return byte[]
*/
- public static byte[] shiftBitsToMSB(byte[] inputBytes, int numBits) {
+ public static byte[] shiftBitsToMSB(final byte[] inputBytes, final int numBits) {
int numBitstoShiftBy = 0, leadZeroesMSB = 8, numEndRestBits = 0;
int size = inputBytes.length;
byte[] shiftedBytes = new byte[size];
* @param numBits - number of bits to be right aligned
* @return byte[]
*/
- public static byte[] shiftBitsToLSB(byte[] inputBytes, int numBits) {
+ public static byte[] shiftBitsToLSB(final byte[] inputBytes, final int numBits) {
int numBytes = inputBytes.length;
int numBitstoShift = numBits % NetUtils.NumBitsInAByte;
byte[] shiftedBytes = new byte[numBytes];
* of bits specified from the input data byte array. The input byte array
* has the bits stored starting from the LSB
*/
- public static void insertBits(byte[] data, byte[] inputdataLSB,
- int startOffset, int numBits) {
+ public static void insertBits(final byte[] data, final byte[] inputdataLSB,
+ final int startOffset, final int numBits) {
byte[] inputdata = shiftBitsToMSB(inputdataLSB, numBits); // Align to
// MSB the
// passed byte
* @throws BufferException when the startOffset and numBits parameters
* are not congruent with the data buffer's size
*/
- public static void checkExceptions(byte[] data, int startOffset, int numBits)
+ public static void checkExceptions(final byte[] data, final int startOffset, final int numBits)
throws BufferException {
int endOffsetByte;
int startByteOffset;