org.jimageanalyst
Class Util

java.lang.Object
  extended by org.jimageanalyst.Util

public final class Util
extends java.lang.Object

Utility class with widely used methods.

Version:
$LastChangedRevision: 2 $
Author:
Oliver J. Siegmar

Field Summary
static float METER_TO_INCH_FACTOR
          Factor to convert meter to inch.
 
Method Summary
static boolean compare(byte[] data1, int offset1, byte[] data2, int offset2, int num)
          Compares two byte arrays with each other.
static int getInt(boolean littleEndian, byte[] data, int offs)
          Converts a four bytes long byte[] to an int value.
static int getIntBigEndian(byte[] data, int offset)
          Converts a four bytes long byte[] to an int value.
static int getIntLittleEndian(byte[] data, int offset)
          Converts a four bytes long byte[] to an int value.
static int getShort(boolean littleEndian, byte[] data, int offset)
          Converts a two bytes long byte[] to an int value.
static int getShortBigEndian(byte[] data, int offset)
          Converts a two bytes long byte[] to an int value.
static int getShortLittleEndian(byte[] data, int offset)
          Converts a two bytes long byte[] to an int value.
static boolean isIn(long item, long... items)
          Checks if an item is in a array of items.
static java.lang.String printHex(byte[] data)
          Returns a human readable hex dump of the given data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

METER_TO_INCH_FACTOR

public static final float METER_TO_INCH_FACTOR
Factor to convert meter to inch.

See Also:
Constant Field Values
Method Detail

getIntBigEndian

public static int getIntBigEndian(byte[] data,
                                  int offset)
Converts a four bytes long byte[] to an int value. The used byte order is big endian (most significant byte first).

Parameters:
data - the byte[] from where the int should be extracted
offset - the position to start reading
Returns:
the int represented by the extracted bytes
See Also:
getIntLittleEndian(byte[], int), getInt(boolean, byte[], int), getShort(boolean, byte[], int), getShortBigEndian(byte[], int), getShortLittleEndian(byte[], int)

getIntLittleEndian

public static int getIntLittleEndian(byte[] data,
                                     int offset)
Converts a four bytes long byte[] to an int value. The used byte order is little endian (least significant byte first).

Parameters:
data - the byte[] from where the int should be extracted
offset - the position to start reading
Returns:
the int represented by the extracted bytes
See Also:
getIntBigEndian(byte[], int), getInt(boolean, byte[], int), getShort(boolean, byte[], int), getShortBigEndian(byte[], int), getShortLittleEndian(byte[], int)

getInt

public static int getInt(boolean littleEndian,
                         byte[] data,
                         int offs)
Converts a four bytes long byte[] to an int value. The used byte order depends on the littleEndian parameter - if true, little endian is used, if false big endian is used.

Parameters:
littleEndian - defines if little or big endian should be used to convert the byte[]
data - the byte[] from where the int should be extracted
offs - the position to start reading
Returns:
the int represented by the extracted bytes
See Also:
getIntBigEndian(byte[], int), getIntLittleEndian(byte[], int), getShort(boolean, byte[], int), getShortBigEndian(byte[], int), getShortLittleEndian(byte[], int)

getShortBigEndian

public static int getShortBigEndian(byte[] data,
                                    int offset)
Converts a two bytes long byte[] to an int value. The used byte order is big endian (most significant byte first).

Parameters:
data - the byte[] from where the int should be extracted
offset - the position to start reading
Returns:
the int represented by the extracted bytes
See Also:
getShortLittleEndian(byte[], int), getShort(boolean, byte[], int), getInt(boolean, byte[], int), getIntBigEndian(byte[], int), getIntLittleEndian(byte[], int)

getShortLittleEndian

public static int getShortLittleEndian(byte[] data,
                                       int offset)
Converts a two bytes long byte[] to an int value. The used byte order is little endian (least significant byte first).

Parameters:
data - the byte[] from where the int should be extracted
offset - the position to start reading
Returns:
the int represented by the extracted bytes
See Also:
getShortBigEndian(byte[], int), getShort(boolean, byte[], int), getInt(boolean, byte[], int), getIntBigEndian(byte[], int), getIntLittleEndian(byte[], int)

getShort

public static int getShort(boolean littleEndian,
                           byte[] data,
                           int offset)
Converts a two bytes long byte[] to an int value. The used byte order depends on the littleEndian parameter - if true, little endian is used, if false big endian is used.

Parameters:
littleEndian - defines if little or big endian should be used to convert the byte[]
data - the byte[] from where the int should be extracted
offset - the position to start reading
Returns:
the int represented by the extracted bytes
See Also:
getShortBigEndian(byte[], int), getShortLittleEndian(byte[], int), getInt(boolean, byte[], int), getIntBigEndian(byte[], int), getIntLittleEndian(byte[], int)

compare

public static boolean compare(byte[] data1,
                              int offset1,
                              byte[] data2,
                              int offset2,
                              int num)
Compares two byte arrays with each other. Returns true if both byte arrays (the compared range) match - false otherwise.

Parameters:
data1 - the first byte array
offset1 - the start position of the first byte array
data2 - the second byte array
offset2 - the start position of the second byte array
num - the amount of bytes to compare
Returns:
true if both byte arrays (the compared range) match - false otherwise

printHex

public static java.lang.String printHex(byte[] data)
Returns a human readable hex dump of the given data.

Parameters:
data - data to hex dump
Returns:
a human readable hex dump of the given data.

isIn

public static boolean isIn(long item,
                           long... items)
Checks if an item is in a array of items. Returns true if the item was found, otherwise false.

Parameters:
item - the item to search for
items - the items to search in
Returns:
true if the item was found, otherwise false.


Copyright © 2006-2007. All Rights Reserved.