com.ecebs.rtd.enabler.common
Class ByteUtils

java.lang.Object
  extended by com.ecebs.rtd.enabler.common.ByteUtils

public class ByteUtils
extends Object

Provides utility methods for interacting with byte arrays

Author:
kyleb

Method Summary
static short b2s(byte b)
          Converts a byte into a short, ignoring sign, i.e.
static String byteArrayToString(byte[] bytes)
          Creates an uppercase string representation of a byte array
static String byteArrayToString(byte[] bytes, int index, int length)
           
static String byteToString(byte b)
           
static byte[] concat(int offset, byte[]... byteArrays)
          Concatonates the provided byte arrays
static byte[] concat(int offset, Integer length, byte[]... byteArrays)
          Concatonates the provided byte arrays
static byte[] concat(int offset, Integer length, List<byte[]> byteArrays)
          Concatonates the provided byte arrays
static byte[] concat(int offset, List<byte[]> byteArrays)
          Concatonates the provided byte arrays.
static boolean isBitSet(int map, int bitNum)
          Checks if the specified bit number is set in the provided map
static byte[] stringToByteArray(String hex)
          Converts a string representation of a chain of bytes into a byte array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

b2s

public static short b2s(byte b)
Converts a byte into a short, ignoring sign, i.e. 0xFF becomes 0x00FF. Default behaviour in java is that 0xFF becomes 0xFFFF.

Parameters:
b - byte to convert
Returns:
Converted byte

byteArrayToString

public static String byteArrayToString(byte[] bytes)
Creates an uppercase string representation of a byte array

Parameters:
bytes - The byte array to convert to a string
Returns:
The string representation of the array, or null if bytes == null

byteToString

public static String byteToString(byte b)

byteArrayToString

public static String byteArrayToString(byte[] bytes,
                                       int index,
                                       int length)

stringToByteArray

public static byte[] stringToByteArray(String hex)
Converts a string representation of a chain of bytes into a byte array. The string must be made up of 2 hexadecimal digits per byte, without spaces, i.e. "0AF251B0E1". The string can be uppercase or lowercase.

Parameters:
bytes - The string of bytes to convert to a byte array
Returns:
The parsed byte array
Throws:
IllegalArgumentException - if the provided hex string is invalid

isBitSet

public static boolean isBitSet(int map,
                               int bitNum)
Checks if the specified bit number is set in the provided map

Parameters:
map - Bit map to be checked
bitNum - Bit number to check
Returns:
True if the bit is set, else false

concat

public static byte[] concat(int offset,
                            byte[]... byteArrays)
Concatonates the provided byte arrays

Parameters:
offset - byte offset to start it
byteArrays - arrays to concatonate
Returns:
An array of the specified length containing the concatonated byte arrays
See Also:
concat(int, Integer, List)

concat

public static byte[] concat(int offset,
                            List<byte[]> byteArrays)
Concatonates the provided byte arrays. Same as calling concat(offset, null, sectors)

Parameters:
offset - byte offset to start it
byteArrays - arrays to concatonate
Returns:
An array of the specified length containing the concatonated byte arrays
See Also:
concat(int, Integer, List)

concat

public static byte[] concat(int offset,
                            Integer length,
                            byte[]... byteArrays)
Concatonates the provided byte arrays

Parameters:
offset - byte offset to start it
length - number of bytes to concatonate (can be null to concatonate all)
byteArrays - arrays to concatonate
Returns:
An array of the specified length containing the concatonated byte arrays
See Also:
concat(int, Integer, List)

concat

public static byte[] concat(int offset,
                            Integer length,
                            List<byte[]> byteArrays)
Concatonates the provided byte arrays

Parameters:
offset - byte offset to start it
length - number of bytes to concatonate (can be null to concatonate all)
byteArrays - arrays to concatonate
Returns:
An array of the specified length containing the concatonated byte arrays


Copyright © 2013 Ecebs Ltd. All Rights Reserved.