Class Utilities


  • public class Utilities
    extends java.lang.Object
    Provides a set of generic utilities used by freetts.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String deleteChar​(java.lang.String fromString, char charToDelete)
      Removes all instances of the specified character from the given String.
      static void dump​(java.io.PrintWriter pw, int padding, java.lang.String string)
      Dumps padded text.
      static boolean getBoolean​(java.lang.String name)
      Gets a boolean property by name.
      static java.io.InputStream getInputStream​(java.net.URL url)
      Returns an input stream for the given URL.
      static java.lang.Integer getInteger​(java.lang.String name, int defaultValue)
      Gets an Integer property by name.
      static java.lang.Long getLong​(java.lang.String name, long defaultValue)
      Gets a long property by name.
      static java.lang.String getProperty​(java.lang.String name, java.lang.String defaultValue)
      Gets a property by name and returns its value.
      static java.lang.String getString​(java.io.DataInputStream dis)
      Inputs a string from a DataInputStream.
      static java.lang.String getString​(java.nio.ByteBuffer bb)
      Inputs a string from a ByteBuffer.
      static void outString​(java.io.DataOutputStream dos, java.lang.String s)
      Outputs a string to the given stream.
      static java.lang.String pad​(int padding)
      Returns a string with the given number of spaces.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, 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
      • deleteChar

        public static java.lang.String deleteChar​(java.lang.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​(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
      • getInputStream

        public static java.io.InputStream getInputStream​(java.net.URL url)
                                                  throws java.io.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:
        java.io.IOException - if there is trouble creating the stream
      • outString

        public static void outString​(java.io.DataOutputStream dos,
                                     java.lang.String s)
                              throws java.io.IOException
        Outputs a string to the given stream.
        Parameters:
        dos - the stream
        s - the string to output
        Throws:
        java.io.IOException - if an I/O error occurs
      • getString

        public static java.lang.String getString​(java.io.DataInputStream dis)
                                          throws java.io.IOException
        Inputs a string from a DataInputStream.
        Parameters:
        dis - the stream
        Returns:
        the string
        Throws:
        java.io.IOException - if an I/O error occurs
      • getString

        public static java.lang.String getString​(java.nio.ByteBuffer bb)
                                          throws java.io.IOException
        Inputs a string from a ByteBuffer.
        Parameters:
        bb - the input byte buffer
        Returns:
        the string
        Throws:
        java.io.IOException - if an I/O error occurs
      • getProperty

        public static java.lang.String getProperty​(java.lang.String name,
                                                   java.lang.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​(java.lang.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 java.lang.Long getLong​(java.lang.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 java.lang.Integer getInteger​(java.lang.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