Package com.sun.speech.freetts.util

# Class Utilities

java.lang.Object
com.sun.speech.freetts.util.Utilities

public class Utilities extends Object
Provides a set of generic utilities used by freetts.

## Method Summary

Modifier and Type
Method
Description
`static String`
`deleteChar(String fromString, char charToDelete)`
Removes all instances of the specified character from the given String.
`static void`
`dump(PrintWriter pw, int padding, String string)`
Dumps padded text.
`static boolean`
`getBoolean(String name)`
Gets a boolean property by name.
`static InputStream`
`getInputStream(URL url)`
Returns an input stream for the given URL.
`static Integer`
`getInteger(String name, int defaultValue)`
Gets an Integer property by name.
`static Long`
`getLong(String name, long defaultValue)`
Gets a long property by name.
`static String`
`getProperty(String name, String defaultValue)`
Gets a property by name and returns its value.
`static String`
`getString(DataInputStream dis)`
Inputs a string from a DataInputStream.
`static String`
`getString(ByteBuffer bb)`
Inputs a string from a ByteBuffer.
`static void`
`outString(DataOutputStream dos, String s)`
Outputs a string to the given stream.
`static String`
`pad(int padding)`
Returns a string with the given number of spaces.
`static String`
`pad(String string, int minLength)`
Pads with spaces or truncates the given string to guarantee that it is exactly the desired length.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### pad

public static 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 String pad(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

### deleteChar

public static String deleteChar(String fromString, char charToDelete)
Removes all instances of the specified character from the given String.

Parameters:
  `fromString` - the String to delete characters from
  `charToDelete` - the character to delete from the given String
Returns:
  a String with all instances of the specified char deleted

### dump

public static void dump(PrintWriter pw, int padding, 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

### getInputStream

public static InputStream getInputStream(URL url) throws IOException
Returns an input stream for the given URL. If the URL is pointing to a local file, returns a file input stream suitable for MemoryMapped IO, otherwise, returns a buffered input stream.

Parameters:
  `url` - the url to open as a stream
Returns:
  the stream associated with the URL
Throws:
  `IOException` - if there is trouble creating the stream

### outString

public static void outString(DataOutputStream dos, String s) throws IOException
Outputs a string to the given stream.

Parameters:
  `dos` - the stream
  `s` - the string to output
Throws:
  `IOException` - if an I/O error occurs

### getString

public static String getString(DataInputStream dis) throws IOException
Inputs a string from a DataInputStream.

Parameters:
  `dis` - the stream
Returns:
  the string
Throws:
  `IOException` - if an I/O error occurs

### getString

public static String getString(ByteBuffer bb) throws IOException
Inputs a string from a ByteBuffer.

Parameters:
  `bb` - the input byte buffer
Returns:
  the string
Throws:
  `IOException` - if an I/O error occurs

### getProperty

public static String getProperty(String name, String defaultValue)
Gets a property by name and returns its value. If the property cannot be found, the default is returned

Parameters:
  `name` - the name of the property
  `defaultValue` - the default value to use if the property cannot be found.
Returns:
  the string value for the property, or the defaultValue if the property cannot be found

### getBoolean

public static boolean getBoolean(String name)
Gets a boolean property by name.

Parameters:
  `name` - the name of the property
Returns:
  If there is no property with the specified name, or if the specified name is empty or null, then false is returned. otherwise the boolean value of the property is returned

### getLong

public static Long getLong(String name, long defaultValue)
Gets a long property by name.

Parameters:
  `name` - the name of the property
  `defaultValue` - the default value to use if the property cannot be found.
Returns:
  the long value for the property, or the defaultValue if the property cannot be found

### getInteger

public static Integer getInteger(String name, int defaultValue)
Gets an Integer property by name.

Parameters:
  `name` - the name of the property
  `defaultValue` - the default value to use if the property cannot be found.
Returns:
  the Integer value for the property, or the defaultValue if the property cannot be found