com.cmpware.cmp
Class Util

java.lang.Object
  extended by com.cmpware.cmp.Util

public class Util
extends java.lang.Object

This class contains various utility methods thay may be used in various different places. These methods are typically static.

Copyright (c) 2004, 2005 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
 
Constructor Summary
Util()
           
 
Method Summary
static int bitsToBytes(int a)
          This routine converts a bit count to a byte count, where the byte count is the minimum number of bytes to hold this many bits.
static java.lang.String[] concatenate(java.lang.String[] a, java.lang.String[] b)
          This method concatenates two arrays of strings.
static java.lang.String get(java.lang.String s1, java.lang.String s2)
          This method returns a string from two input strings.
static java.lang.String getHostName()
          This method returns the host name.
static org.eclipse.swt.graphics.Image getImage(java.lang.String pathName)
          This method returns a bitmap image.
static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(java.lang.String pathName)
          This method returns a bitmap image descriptor.
static java.lang.String getPath(java.lang.String pathname)
          This method returns the path from a full pathname string.
static long pack(int a, int b)
          This method packs two 32-bit integers into a 64-bit long.
static int parseInt(java.lang.String s)
          This method parses a string and returns an integer.
static byte[] readFile(java.lang.String fileName)
          This method reads in a text file and returns the contents as an ArrayList with one line of text per entry.
static java.lang.String[] readTextFile(java.lang.String fileName)
          This method read in a text file and returns it as an array of strings.
static int signExtend(int a, int bits)
          This method is used to take a value 'a' of bit length 'bits' and sign extend it, making it a proper signed integer value.
static long signExtend(long a, int bits)
          This method is used to take a value 'a' of bit length 'bits' and sign extend it, making it a proper signed integer value.
static int signExtend16(int x)
          This method returns an 16-bit value sign extended to to a 32-bit integer.
static int signExtend8(int x)
          This method returns an 8-bit value sign extended to to a 32-bit integer.
static int swap(int a)
          This static method swaps the bytes in a 32-bit word.
static long swap(long a)
          This static method swaps the bytes in a 64-bit word.
static short swap(short a)
          This static method swaps the bytes in a 16-bit word.
static java.lang.String toHexString(byte b)
          This method returns a two character string representing a byte.
static java.lang.String toHexString(byte[] b)
          This method returns a hexadecimal String representation of an array of bytes.
static java.lang.String toHexString(byte[] b, int index, int bytes)
          This method returns a hexadecimal String representation from a subset of an array of bytes.
static java.lang.String toHexString(int i)
          This method returns an eight character string representing a 32-bit int.
static java.lang.String toHexString(long i)
          This method returns a sixteen character string representing a 64-bit long.
static java.lang.String toHexString(short b)
          This method returns a four character string representing a 16-bit short.
static long toLong(byte[] b, boolean endian)
          This method converts a byte array to a long.
static char toPrintable(byte b)
          This method convers a byte to a printable character.
static long unsigned(int a)
          When Java converts an int to a long, sign extension is performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values
Constructor Detail

Util

public Util()
Method Detail

readFile

public static byte[] readFile(java.lang.String fileName)
                       throws java.io.IOException
This method reads in a text file and returns the contents as an ArrayList with one line of text per entry.

Parameters:
fileName - The name of the input text file.
Returns:
This method reads in a text file and returns the contents as a String array.
Throws:
java.io.IOException - if an error is encountered opening, reading of closing the input file.

readTextFile

public static java.lang.String[] readTextFile(java.lang.String fileName)
                                       throws java.io.IOException
This method read in a text file and returns it as an array of strings.

Parameters:
fileName - The name of the file to be read.
Returns:
This method returns the contents of a text file as an array of strings.
Throws:
java.io.IOException - if an error is encountered opening, reading of closing the input file.

get

public static final java.lang.String get(java.lang.String s1,
                                         java.lang.String s2)
This method returns a string from two input strings.

Parameters:
s1 - The first input string.
s2 - The second input string.
Returns:
The combined string is returned.

getPath

public static final java.lang.String getPath(java.lang.String pathname)
This method returns the path from a full pathname string. This is basically everything before the last front or back slash.

Parameters:
pathname - The full pathname of a file.
Returns:
This method returns the path from a full pathname string.

getImage

public static final org.eclipse.swt.graphics.Image getImage(java.lang.String pathName)
This method returns a bitmap image.

Parameters:
pathName - The pathname to the bitmapge image file from the bundle root ("/").
Returns:
This method returns the bitmap image, or a null if an error was encountered.

getImageDescriptor

public static final org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(java.lang.String pathName)
This method returns a bitmap image descriptor.

Parameters:
pathName - The pathname to the bitmapge image descriptor from the bundle root ("/").
Returns:
This method returns the bitmap image descriptor, or a null if an error was encountered.

getHostName

public static final java.lang.String getHostName()
This method returns the host name.

Returns:
This method returns the host name.

parseInt

public static int parseInt(java.lang.String s)
                    throws java.lang.NumberFormatException
This method parses a string and returns an integer. If the string begins with "0x", it is assumed to be a hexadecimal number. Otherwise an integer is assumed.

Parameters:
s - The string to be converted into an integer.
Returns:
This method returns the integer representation of the string s.
Throws:
java.lang.NumberFormatException - if the string is not a proper decimal or hexadecimal integer.

signExtend8

public static final int signExtend8(int x)
This method returns an 8-bit value sign extended to to a 32-bit integer.

Parameters:
x - The input value.
Returns:
This method returns an 8-bit value sign extended to to a 32-bit integer.

signExtend16

public static final int signExtend16(int x)
This method returns an 16-bit value sign extended to to a 32-bit integer.

Parameters:
x - The input value.
Returns:
This method returns an 16-bit value sign extended to to a 32-bit integer.

signExtend

public static int signExtend(int a,
                             int bits)
This method is used to take a value 'a' of bit length 'bits' and sign extend it, making it a proper signed integer value.

Parameters:
a - The value to be sign extended.
bits - the number of bits in the input value.
Returns:
this method returns the value a, signed extended for a given number of bits.

signExtend

public static long signExtend(long a,
                              int bits)
This method is used to take a value 'a' of bit length 'bits' and sign extend it, making it a proper signed integer value. This is for 64-bit long integers.

Parameters:
a - The value to be sign extended.
bits - the number of bits in the input value.
Returns:
this method returns the value a, signed extended for a given number of bits.

bitsToBytes

public static int bitsToBytes(int a)
This routine converts a bit count to a byte count, where the byte count is the minimum number of bytes to hold this many bits.

Parameters:
a - The number of bits.
Returns:
This method returns the number of bytes necessary to hold the number of bits in the input parameter.

concatenate

public static java.lang.String[] concatenate(java.lang.String[] a,
                                             java.lang.String[] b)
This method concatenates two arrays of strings.

Parameters:
a - the first array of strings.
b - the second array of strings.
Returns:
this method returns the concatenated array of the two string arrays.

toLong

public static long toLong(byte[] b,
                          boolean endian)
This method converts a byte array to a long.

Parameters:
b - The byte array. If this araray is longer than eight bytes, the result is undefined.
endian - The endian of the memory.
Returns:
this method converts a byte array to a long.

swap

public static short swap(short a)
This static method swaps the bytes in a 16-bit word. This is used to convert the 'endian' byte ordering.

Parameters:
a - The 16-bit input value.
Returns:
This method returns the 16-bit input value 'a' with its bytes swapped.

swap

public static int swap(int a)
This static method swaps the bytes in a 32-bit word. This is used to convert the 'endian' byte ordering.

Parameters:
a - The 32-bit input value.
Returns:
This method returns the 32-bit input value 'a' with hits bytes swapped.

swap

public static long swap(long a)
This static method swaps the bytes in a 64-bit word. This is used to convert the 'endian' byte ordering.

Parameters:
a - The 64-bit input value.
Returns:
This method returns the 64-bit input value 'a' with hits bytes swapped.

toPrintable

public static char toPrintable(byte b)
This method convers a byte to a printable character. If the byte is not a printable ASCII character, a '.' (dot) character is returned. This method is used primarily in the memory hex dump.

Parameters:
b - The byte to be converted to a printable character.
Returns:
This method returns the printable character representation of the input byte. If the character is not printable, a '.' (dot) character is returned.

toHexString

public static java.lang.String toHexString(byte b)
This method returns a two character string representing a byte.

Parameters:
b - The byte to be converted into a string.
Returns:
This method returns a two character string representing a byte.

toHexString

public static java.lang.String toHexString(short b)
This method returns a four character string representing a 16-bit short.

Parameters:
b - The 16-bit short to be converted into a string.
Returns:
This method returns a four character string representing a 16-bit short.

toHexString

public static java.lang.String toHexString(int i)
This method returns an eight character string representing a 32-bit int.

Parameters:
i - The 32-bit int to be converted into a string.
Returns:
This method returns an eight character string representing a 32-bit int.

toHexString

public static java.lang.String toHexString(long i)
This method returns a sixteen character string representing a 64-bit long.

Parameters:
i - The 64-bit long to be converted into a string.
Returns:
This method returns a sizteen character string representing a 64-bit long.

toHexString

public static java.lang.String toHexString(byte[] b)
This method returns a hexadecimal String representation of an array of bytes.

Parameters:
b - The byte array to be converted into a string.
Returns:
This method returns a hexadecimal String representation of an array of bytes.

toHexString

public static java.lang.String toHexString(byte[] b,
                                           int index,
                                           int bytes)
This method returns a hexadecimal String representation from a subset of an array of bytes.

Parameters:
b - The byte array.
index - the start of the byte array.
bytes - the number of bytes in the returned hex string.
Returns:
This method returns a hexadecimal String representation of an array of bytes.

pack

public static long pack(int a,
                        int b)
This method packs two 32-bit integers into a 64-bit long. The 'a' parameter is the upper 32 bits and the 'b' parameter is the lower 32 bits.

Parameters:
a - the upper 32 bits of the returned long.
b - the lower 32 bits of the returned long.
Returns:
a 64-bit long value is returned with the upper 32 bits coming from the 'a' parameter and the lower 32 bits coming from the 'b' parameter.

unsigned

public static long unsigned(int a)
When Java converts an int to a long, sign extension is performed. This method returns a long representation of an int interpreted as an unsigned int. In other words, the lower 32 bits of the returned long are the same as the integer, and the upper 32 bits are always zero.

Parameters:
a - the integer value.
Returns:
the long representation of the integer value, represented as an unsigned value, is returned.