Package com.sun.speech.freetts.util
Class Utilities
java.lang.Object
com.sun.speech.freetts.util.Utilities
Provides a set of generic utilities used by freetts.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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
Pads with spaces or truncates the given string to guarantee that it is exactly the desired length.
-
Method Details
-
pad
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
Pads with spaces or truncates the given string to guarantee that it is exactly the desired length.- Parameters:
string
- the string to be paddedminLength
- the desired length of the string- Returns:
- a string of length conntaining string padded with whitespace or truncated
-
deleteChar
Removes all instances of the specified character from the given String.- Parameters:
fromString
- the String to delete characters fromcharToDelete
- the character to delete from the given String- Returns:
- a String with all instances of the specified char deleted
-
dump
Dumps padded text. This is a simple tool for helping dump text with padding to a Writer.- Parameters:
pw
- the stream to send the outputpadding
- the number of spaces in the stringstring
- the string to output
-
getInputStream
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
Outputs a string to the given stream.- Parameters:
dos
- the streams
- the string to output- Throws:
IOException
- if an I/O error occurs
-
getString
Inputs a string from a DataInputStream.- Parameters:
dis
- the stream- Returns:
- the string
- Throws:
IOException
- if an I/O error occurs
-
getString
Inputs a string from a ByteBuffer.- Parameters:
bb
- the input byte buffer- Returns:
- the string
- Throws:
IOException
- if an I/O error occurs
-
getProperty
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 propertydefaultValue
- 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
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
Gets a long property by name.- Parameters:
name
- the name of the propertydefaultValue
- 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
Gets an Integer property by name.- Parameters:
name
- the name of the propertydefaultValue
- 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
-