edu.cmu.sphinx.util
Class Utilities

java.lang.Object
  extended byedu.cmu.sphinx.util.Utilities

public class Utilities
extends java.lang.Object

Provides a set of generic utilities


Method Summary
static java.lang.String doubleToScientificString(double number, int fractionDigits)
          Returns the string representation of the given double value in normalized scientific notation.
static void dump(java.io.PrintWriter pw, int padding, java.lang.String string)
          Dumps padded text.
static void dumpMemoryInfo(java.lang.String msg)
          Dumps out memory information
static boolean isCepstraFileBigEndian(java.lang.String filename)
          Returns true if the given binary cepstra file is in big-endian format.
static void objectTracker(java.lang.String name, int count)
          utility method for tracking object counts
static java.lang.String pad(double val, int minLength)
          Pads with spaces or truncates the given double to guarantee that it is exactly the desired length.
static java.lang.String pad(int padding)
          Returns a string with the given number of spaces.
static java.lang.String pad(int val, int minLength)
          Pads with spaces or truncates the given int to guarantee that it is exactly the desired length.
static java.lang.String pad(java.lang.String string, int minLength)
          Pads with spaces or truncates the given string to guarantee that it is exactly the desired length.
static float readLittleEndianFloat(java.io.DataInputStream dataStream)
          Reads the next float from the given DataInputStream, where the data is in little endian.
static int readLittleEndianInt(java.io.DataInputStream dataStream)
          Reads the next little-endian integer from the given DataInputStream.
static float swapFloat(float floatValue)
          Byte-swaps the given float to the other endian.
static int swapInteger(int integer)
          Byte-swaps the given integer to the other endian.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

pad

public static java.lang.String pad(int padding)
Returns a string with the given number of spaces.

Parameters:
padding - the number of spaces in the string
Returns:
a string of length 'padding' containg only the SPACE char.

pad

public static java.lang.String pad(java.lang.String string,
                                   int minLength)
Pads with spaces or truncates the given string to guarantee that it is exactly the desired length.

Parameters:
string - the string to be padded
minLength - the desired length of the string
Returns:
a string of length conntaining string padded with whitespace or truncated

pad

public static java.lang.String pad(int val,
                                   int minLength)
Pads with spaces or truncates the given int to guarantee that it is exactly the desired length.

Parameters:
val - the val to be padded
minLength - the desired length of the string
Returns:
a string of length conntaining string padded with whitespace or truncated

pad

public static java.lang.String pad(double val,
                                   int minLength)
Pads with spaces or truncates the given double to guarantee that it is exactly the desired length.

Parameters:
val - the val to be padded
minLength - the desired length of the string
Returns:
a string of length conntaining string padded with whitespace or truncated

dump

public static void dump(java.io.PrintWriter pw,
                        int padding,
                        java.lang.String string)
Dumps padded text. This is a simple tool for helping dump text with padding to a Writer.

Parameters:
pw - the stream to send the output
padding - the number of spaces in the string
string - the string to output

objectTracker

public static void objectTracker(java.lang.String name,
                                 int count)
utility method for tracking object counts

Parameters:
name - the name of the object
count - the count of objects

dumpMemoryInfo

public static void dumpMemoryInfo(java.lang.String msg)
Dumps out memory information

Parameters:
msg - addditional text for the dump

doubleToScientificString

public static java.lang.String doubleToScientificString(double number,
                                                        int fractionDigits)
Returns the string representation of the given double value in normalized scientific notation. The fractionDigits argument gives the number of decimal digits in the fraction portion. For example, if fractionDigits is 4, then the 123450 will be "1.2345e+05". There will always be two digits in the exponent portion, and a plus or minus sign before the exponent.

Parameters:
number - the double to convert
fractionDigits - the number of digits in the fraction part, e.g., 4 in "1.2345e+05".
Returns:
the string representation of the double in scientific notation

isCepstraFileBigEndian

public static boolean isCepstraFileBigEndian(java.lang.String filename)
                                      throws java.io.IOException
Returns true if the given binary cepstra file is in big-endian format. It assumes that the first 4 bytes of the file tells you how many 4-byte floating point cepstra values are in the file.

Parameters:
filename - the cepstra file name
Returns:
true if the given binary cepstra file is big-endian
Throws:
java.io.IOException

readLittleEndianFloat

public static float readLittleEndianFloat(java.io.DataInputStream dataStream)
                                   throws java.io.IOException
Reads the next float from the given DataInputStream, where the data is in little endian.

Parameters:
dataStream - the DataInputStream to read from
Returns:
a float
Throws:
java.io.IOException

readLittleEndianInt

public static int readLittleEndianInt(java.io.DataInputStream dataStream)
                               throws java.io.IOException
Reads the next little-endian integer from the given DataInputStream.

Parameters:
dataStream - the DataInputStream to read from
Returns:
an integer
Throws:
java.io.IOException

swapInteger

public static int swapInteger(int integer)
Byte-swaps the given integer to the other endian. That is, if this integer is big-endian, it becomes little-endian, and vice-versa.

Parameters:
integer - the integer to swap

swapFloat

public static float swapFloat(float floatValue)
Byte-swaps the given float to the other endian. That is, if this float is big-endian, it becomes little-endian, and vice-versa.

Parameters:
floatValue - the float to swap