org.resoa.util
Class ByteBufferUtils

java.lang.Object
  extended by org.resoa.util.ByteBufferUtils

public class ByteBufferUtils
extends java.lang.Object

Helper functions for conversion of unsigned bytes to integer

Author:
Gleb Shulman

Constructor Summary
ByteBufferUtils()
           
 
Method Summary
static byte[] fromByteArrayString(java.lang.String source)
          Converts a HEX string to byte array
static byte[] fromByteArrayString(java.lang.String source, java.lang.String delimiter)
          create a byte array from string. unspecific data is set to null
static int IntFromUnsignedByte(byte b)
          convert a unsigned byte into integer value
static java.lang.String toHexString(byte b)
          converts a single byte to HEX format (lower case)
static java.lang.String toHexString(byte[] byteArray)
          represent byte[] array as HEX string
static java.lang.String toHexString(byte[] buf, int offset, int length)
          represent a part of byte[] array as string
static java.lang.String toHexString(byte[] data, java.lang.String delimiter, boolean toUpperCase)
          Returns a HEX string of a byte array
static java.lang.String toHexString(java.nio.ByteBuffer buffer)
          Creates a HEX String from ByteBuffer array
static byte UnsignedByteFromInt(int i)
          convert integer to byte in optimistic way, in case of outside value 0..255 it returns 0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferUtils

public ByteBufferUtils()
Method Detail

UnsignedByteFromInt

public static byte UnsignedByteFromInt(int i)
convert integer to byte in optimistic way, in case of outside value 0..255 it returns 0

Parameters:
i - the integer byte value to convert
Returns:
the byte value

IntFromUnsignedByte

public static int IntFromUnsignedByte(byte b)
convert a unsigned byte into integer value

Parameters:
b - the byte value
Returns:
the integer value of the unsigned byte

toHexString

public static java.lang.String toHexString(java.nio.ByteBuffer buffer)
Creates a HEX String from ByteBuffer array

Parameters:
buffer - the ByteBuffer
Returns:
the HEX String

toHexString

public static java.lang.String toHexString(byte[] byteArray)
represent byte[] array as HEX string

Parameters:
byteArray - the bytes
Returns:
the HEX String

toHexString

public static java.lang.String toHexString(byte[] buf,
                                           int offset,
                                           int length)
represent a part of byte[] array as string

Parameters:
buf -
offset -
length -
Returns:
the HEX String

toHexString

public static java.lang.String toHexString(byte[] data,
                                           java.lang.String delimiter,
                                           boolean toUpperCase)
Returns a HEX string of a byte array

Parameters:
data - the array
delimiter - the delimiter, set between each HEX byte
toUpperCase - true if converted to UpperCase
Returns:
the HEX String

toHexString

public static java.lang.String toHexString(byte b)
converts a single byte to HEX format (lower case)

Parameters:
b - the byte
Returns:
the HEX representation of the Byte

fromByteArrayString

public static byte[] fromByteArrayString(java.lang.String source)
Converts a HEX string to byte array

Parameters:
source - the HEX based representation
Returns:
the byte array

fromByteArrayString

public static byte[] fromByteArrayString(java.lang.String source,
                                         java.lang.String delimiter)
create a byte array from string. unspecific data is set to null

Parameters:
source - the source string
delimiter - the delimiter in source
Returns:
the byte array


Copyright © 2005-2011 The Resoa Project, resoa.org. All Rights Reserved.