Package rma.util

Class RMAIO

java.lang.Object
rma.util.RMAIO

public final class RMAIO extends Object
  • Field Details

    • ID_SEPARATOR

      public static final String ID_SEPARATOR
      See Also:
    • separator

      public static final String separator
      See Also:
    • invalidFileNameChars

      public static char[] invalidFileNameChars
    • intervalNames

      public static String[] intervalNames
      parse time strings and return int seconds
    • intervalValues

      public static int[] intervalValues
  • Method Details

    • getRGBString

      public static String getRGBString(Color c)
    • getIPUrl

      public static String getIPUrl(String inputUrl)
      return the String url that has the IP address in it instead of a hostname
      Parameters:
      inputUrl - the url that this object is bound in the registry with
      Returns:
      the String url that has the IP address in it instead of a hostname
    • parseBoolean

      public static boolean parseBoolean(String value, boolean defaultValue)
      Parses the argument string value into a boolean through case insensitive matching on the following.
       "true", "t", "on", "1","yes"
       "false", "f","off","0","no".
       
      Parameters:
      value - The string value to be parsed
      defaultValue - returned if the string value does not match
      Returns:
      true or false
    • parseRGBString

      public static Color parseRGBString(String rgbStr)
    • parseColorString

      public static Color parseColorString(String colorString)
      return the Color specified by colorString
      Parameters:
      colorString - either a RGB value r,g,b or a color name "blue"
      Returns:
      the Color specified by colorStringg
    • color2String

      public static String color2String(Color c)
      given a Color return it's string representation if it's a now color (Color.red) or a darker(Color.red.darker()) or brigher (Color.red.brigher()) version of a color return darkcolor or lightcolor ie. darkred or lightred. if it's not any of those return a r,g,b string
      Returns:
      a string representation of the color.
    • getRelativePath

      public static String getRelativePath(String basePath, String fullPath)
      Returns a path that is relative to the base path. If the base path does not occur in the full path then the full path is returned. For example base = j:/apps/base/baldeagle full = j:/apps/base/baldealge/model/index.dbf the relative path is model.index.dbf
      Parameters:
      basePath - - the path to use that is used for comparison
      fullPath - - the full file path that will be turned into the relative path
    • getRelativePath

      public static String getRelativePath(String basePath, String fullPath, boolean useDotDot, boolean useDotSlash)
      Returns the relative path that addresses from base path to full path optionally including using '..' if the base path does not occur in the full path. If the full path is not addressible from the base path (for example, different drive letters) then the original full path is returned.
      Parameters:
      basePath - - the working directory for the relative path.
      fullPath - - the full file path that will be converted to a relative path.
      traverseDotDot - - flag to turn on using '..' in the relative path.
      See Also:
      • RMAIO.getRelativePath
    • isRelativePathTo

      public static boolean isRelativePathTo(String basePath, String fullPath)
      Returns a boolean flag that indicates if the fullpath is contained in the base path. I.e. the full path is a file or sub-directory contained underneath the base path.
      Parameters:
      basePath - - the path to use that is used for comparison
      fullPath - - the full file path that will be turned into the relative path
      Returns:
    • getType

      public static String getType(String line, String delim)
      Parses the expression TYPEPARAM and returns the string and returns the TYPE. If the DELIM does not exist the original line is returned
    • getParam

      public static String getParam(String line, String delim)
    • getParam

      public static String getParam(String line, String delim, boolean trim)
      Parses line and returns the portion after delim. If line does not contain delim the empty String is returned.
      Parameters:
      line - A String of the form TYPEPARAM
      delim - the delimiting substring to search for
      trim - method should trim before returning.
      Returns:
      portion of line which occurs after delim.
    • parseInt

      public static int parseInt(String str, int defaultVal)
      Parses the given string and converts to an integer. If an error occures in the parse of the string, the default value is returned
      Parameters:
      str - the string to parse
      defaultVal - the default value to use if the parse failes.
    • parseInt

      public static int parseInt(String str)
      Parses a string and returns the int value of that string. If an exception occures when parsing the string, RMAConst.UNDEF_INT is returned.
    • parseLong

      public static long parseLong(String str, long defaultVal)
      Parses the given string and converts to an long. If an error occures in the parse of the string, the default value is returned
      Parameters:
      str - the string to parse
      defaultVal - the default value to use if the parse failes.
    • parseLong

      public static long parseLong(String str)
      Parses a string and returns the long value of that string. If an exception occures when parsing the string, RMAConst.UNDEF_LONG is returned.
    • parseFloat

      public static float parseFloat(Object obj, float def)
    • parseFloat

      public static float parseFloat(String flt, float def)
    • parseFloat

      public static float parseFloat(String str)
    • parseDouble

      public static double parseDouble(String str, double def)
    • parseDouble

      public static double parseDouble(String str)
    • toString

      public static String toString(int val)
    • toString

      public static String toString(float val)
    • toString

      public static String toString(double val)
    • toTable

      public static String toTable(double val)
      static public String toTable(Object obj) { if (obj instanceof String) return obj.toString(); else if (obj instanceof Double) return toTable(((Double)obj).doubleValue()); else if (obj instanceof Integer) return toTable(((Integer)obj).intValue()); else if (obj instanceof Float) return toTable(((Float)obj).floatValue()); else return(""); }
    • toTable

      public static String toTable(int val)
    • toTable

      public static String toTable(float val)
    • toTableObj

      public static Object toTableObj(Double val)
    • toTableObj

      public static Object toTableObj(Integer val)
    • toTableObj

      public static Object toTableObj(Float val)
    • fout

      public static void fout(BufferedWriter out, String txt)
    • sprintf

      public static StringBuffer sprintf(int bufSize, Object inputStr)
    • sprintf

      public static StringBuffer sprintf(int bufSize, int num)
    • sprintf

      public static StringBuffer sprintf(int bufSize, double num)
    • copyHashToVector

      public static void copyHashToVector(Hashtable ht, Vector vec)
      Places the reference *keys* of the java.util.Hashtable into the java.util.Vector. PSM - Note that a java.util.Hashtable also has a listing of elements that is not accounted for.
    • parseDouble

      public static double parseDouble(Object dbl)
    • parseDouble

      public static double parseDouble(Object dbl, double def)
      Writen by SJN. Used for table manipulations. Checks to see if the Object is null. If so returns the Udefined Value If not returns the representation type.
    • parseDouble

      public static double parseDouble(ParamDouble dbl)
    • parseDouble

      public static double parseDouble(ParamDouble dbl, double def)
    • parseLong

      public static long parseLong(Object longvalue)
    • parseInt

      public static int parseInt(Object integer)
    • parseFloat

      public static float parseFloat(Object flt)
    • round

      public static double round(double dbl, int precision)
      Takes as input a double value to round and the precision to round it to. Returns a double value that is the rounded version of input double. For example 10.345 with 3 units of precision -> 10.35.
      If the incomming double value is an undefined value then RMAConst.UNDEF_DOUBLE is returned
      Parameters:
      dbl - the value to round
      precision - to round to.
    • setPrecision

      public static String setPrecision(double dbl, int precision)
      Set of function similar to toTable() but allow the caller to set the precision of the number and the converts it to a string
    • setPrecision2

      public static String setPrecision2(double dbl, int precision)
    • setPrecision3

      public static String setPrecision3(double dbl)
      figure out the precision of a number and return it.
      Parameters:
      dbl -
      Returns:
    • findPrecision

      public static int findPrecision(double val)
      find the precision of a number
      Parameters:
      val -
    • compareArrays

      public static boolean compareArrays(double[] array1, double[] array2, double precision)
      Returns an int representing the comparison of val to compareTo using precision. true all the numbers in the array are equal. false one or more numbers in the array are not within the precision compare than compareTo.
      Parameters:
      array1 -
      array2 -
      precision -
      Returns:
      true if the array values are the same.
    • compareTo

      public static int compareTo(double val, double compareTo, double precision)
      Returns an int representing the comparison of val to compareTo using precision. 0 = the numbers equal. 1 = val is not within the precision compare and is greater than compareTo. -1 = val is not withing the precision compare and is less than compareTo.
    • parseDate

      public static long parseDate(String date)
      Returns a UTC long representing the java.util.Date ms long value that corresponds to the argument date String. The time zone used is the default time zone. The date String must be in the following formats:
      HHmm ddMonthyyyy
      or
      ddMonthyyyy HHmm
      See Also:
    • parseDate

      public static long parseDate(String date, TimeZone tz)
      Returns a UTC long representing the java.util.Date ms long value that corresponds to the argument date String and the argument time zone.
      Parameters:
      date - must be in the following formats: "HHmm ddMonthyyyy or 'ddMonthyyyy HHmm'.
      tz - the time zone of the date argument, if null the default time zone is used.
    • formatDate

      public static String formatDate(long time, String format)
    • formatDate

      public static String formatDate(long time, TimeZone timezone)
    • formatDate

      public static String formatDate(long time, String format, String strTimezone)
    • formatDate

      public static String formatDate(long time, String format, TimeZone timezone)
    • formatDate

      public static String formatDate(long time)
    • trimToFilename

      public static String trimToFilename(String filepath)
    • substring

      public static String substring(String string, String subString, boolean pre)
      returns a new String that is a substring of string. The substring uses subString to find the location in string to substring. if pre is true then it substrings from 0 to the beginging of subString. if pre is false then it substrings from subString start plus subString.length to the end of string

      Examples

      substring("hamburger", "b", true) returns "ham" substring("hamburger", "bur", false) return "ger"

      Returns:
      a new String, or an empty String if subString or string is null or string doesn't contain subString
      See Also:
    • fillString

      public static StringBuffer fillString(int bufSize, char c)
    • center

      public static StringBuffer center(int bufSize, String inputStr)
    • center

      public static StringBuffer center(int bufSize, String inputStr, char fill)
    • rightJustify2

      public static StringBuffer rightJustify2(int bufsize, String inputStr)
      Takes a string a puts it is a StringBuffer where the given string is right justifies
    • rightJustify

      public static StringBuffer rightJustify(int bufsize, String inputStr)
      Takes a string a puts it is a StringBuffer where the given string is right justifies
    • leftJustify

      public static StringBuffer leftJustify(int bufsize, String inputStr)
      Takes a string a puts it is a StringBuffer where the given string is left justified
    • leftJustify

      public static StringBuffer leftJustify(int bufsize, String inputStr, char fill)
      Takes a string a puts it is a StringBuffer where the given string is left justified fill with the character fill
    • subtractUndef

      public static String subtractUndef(double param1, double param2, int precission)
      Returns a string representation of a double with a given precission
    • getSystemHomeDirectory

      public static String getSystemHomeDirectory()
    • getPropertyFilePath

      public static String getPropertyFilePath(String filename)
    • getJavaVersion

      public static int getJavaVersion()
      return the constant that represents our current JAVA version
    • getOSType

      public static int getOSType()
      return the constant that represents our current OS type
    • postInfo

      public static void postInfo(Component parent, String msg)
    • postError

      public static void postError(Component parent, String msg)
    • postError

      public static void postError(Component parent, String msg, String title)
    • postWarning

      public static void postWarning(Component parent, String msg)
    • postWarning

      public static void postWarning(Component parent, String msg, String title)
    • postYesNoWarning

      public static int postYesNoWarning(Component parent, String msg)
    • postYesNoWarning

      public static int postYesNoWarning(Component parent, String msg, String title)
    • postYesNoMessage

      public static int postYesNoMessage(Component parent, String msg, String title)
    • postYesNoCancelWarning

      public static int postYesNoCancelWarning(Component parent, String msg)
    • postYesNoCancelWarning

      public static int postYesNoCancelWarning(Component parent, String msg, String title)
    • postOkCancelWarning

      public static int postOkCancelWarning(Component parent, String msg)
    • postOkCancelWarning

      public static int postOkCancelWarning(Component parent, String msg, String title)
    • parsePathName

      public static String parsePathName(String pathName)
      given a path with an embedded $CWMS_HOME return the path with the $CWMS_HOME or CWMS_HOME property replaced with the value of the property.
    • parsePathEnvVars

      public static String parsePathEnvVars(String pathName)
      given a path with an embedded $APPDATA return the path with the $APPDATA or APPDATA env var replaced with the value of the env var.
    • trimSeparators

      public static void trimSeparators(StringBuffer sb)
    • userNameFromUserId

      public static String userNameFromUserId(String userId)
    • userNameToFileName

      public static String userNameToFileName(String userName)
    • replace

      public static String replace(String str, String oldChars, String newChars)
      replace oldChars in str with newChars
      Returns:
      string with replaced chars
    • removeNonPrintable

      public static String removeNonPrintable(String s)
      remove non-printable characters from the String
      Parameters:
      s - the String to remove the non-printable characters from
      Returns:
      See Also:
    • removeChar

      public static String removeChar(String s, char c)
    • removeTrailingChars

      public static String removeTrailingChars(String s, char c)
    • countCharacters

      public static int countCharacters(String s, char charToCount)
      count the number of times character charToCount occurs in String s
      Parameters:
      s - the String to count chars in
      charToCount - the character to look for
      Returns:
      the number of times charToCount occurs in s
    • trimTrailing

      public static String trimTrailing(String s, char trailingChar)
      trim off all trailing characters trailingChar from String s
      Parameters:
      s - the String to trim trailingChar from
      trailingChar - the char to remove
      Returns:
      the new String
    • trim

      public static String trim(String s, char trimChar)
      trim off all characters trimChar from String s
      Parameters:
      s - the String to trim trailingChar from
      trimChar - the char to remove
      Returns:
      the new String
    • trim

      public static String trim(String s, char trailingChar, boolean onlyTrailing)
    • removeCharAt

      public static String removeCharAt(String s, int pos)
    • getNumChars

      public static int getNumChars(String s, char c)
      return the number of times character c appears in String s
    • parseStringWithQuotes

      public static Vector parseStringWithQuotes(String line)
      Parses a string, like string.split() does, but respects quoted portions of the string, treating them like a complete part. Quotes are removed in returned segments For example: loc="South Marina" param=Flow, vers="Run 1" returns: loc=South Marina param=Flow vers=Run 1
      Parameters:
      line - String
      Returns:
      Vector
    • getComputerName

      public static String getComputerName()
      get the local computer name. Check the environment first, then the network
      Returns:
      the computer name or "Unknown" if it can't be determined.
    • parseIntervalName

      public static int parseIntervalName(String intvName)
    • endianSwap

      public static void endianSwap(short[] array)
    • makeAbsolutePath

      public static String makeAbsolutePath(String basePath, String relPath)
    • isFullPath

      public static boolean isFullPath(String path)
      check to see if the path is a full or relative path
    • getCheckSum

      public static long getCheckSum(File file)
    • arrayMin

      public static double arrayMin(double[] array)
      return the minimum value for the array array
      Parameters:
      array - the array to find the minimum value in
      Returns:
      the minimum value in the array. RMAConst.UNDEF_INT if the array is null. Integer.MAX_VALUE if the array has a length of 0.
    • arrayMax

      public static double arrayMax(double[] array)
      return the maximum value for the array array
      Parameters:
      array - the array to find the maximum value in
      Returns:
      the maximum value in the array. RMAConst.UNDEF_INT if the array is null. Integer.MIN_VALUE if the array has a length of 0.
    • arrayMin

      public static int arrayMin(int[] array)
      return the minimum value for the array array
      Parameters:
      array - the array to find the minimum value in
      Returns:
      the minimum value in the array. RMAConst.UNDEF_INT if the array is null. Integer.MAX_VALUE if the array has a length of 0.
    • arrayMax

      public static int arrayMax(int[] array)
      return the maximum value for the array array
      Parameters:
      array - the array to find the maximum value in
      Returns:
      the maximum value in the array. RMAConst.UNDEF_INT if the array is null. Integer.MIN_VALUE if the array has a length of 0.
    • indexOf

      public static int indexOf(int[] array, int key)
      Scan the int array array for presence of the int key. This method is intended for searches of unsorted integer arrays.
      Parameters:
      array - the array to scan find the int key.
      Returns:
      the index of the first occurrence of the argument key. Returns -1 if not found.
    • concatPath

      public static String concatPath(String path, String newPart)
      add a new file path part to a file path. If there is no trailing slash on path then one will be added before appending newPart
      Parameters:
      path - the existing path
      newPart - the new part to add to the path
      Returns:
      the path with the newPart added to it.
    • getFileNameNoExtension

      public static String getFileNameNoExtension(String path)
      return the file name portion of the path with no extension.
      Parameters:
      path - the path
      Returns:
      the file name portion.
    • getPathNoExtension

      public static String getPathNoExtension(String path)
      return the path with no file extension.
      Parameters:
      path - the path
      Returns:
      the path with no file extension
    • getFileFromPath

      public static String getFileFromPath(String path)
      return the file name portion of the path with the extension (if it has one)
      Parameters:
      path - the path
      Returns:
      the last portion of the path. Portions of the path are separated by the separator character. if the path is null a null is returned. if no separator characters are found then the entire path is returned.
    • getDirectoryFromPath

      public static String getDirectoryFromPath(String path)
      return the parent directory portion of the path

      The parent of path consists of the path's prefix, if any, and each name in the path's name sequence except for the last. path name sequences are separated by separator character.

      Parameters:
      path - the pathname
      Returns:
      The pathname string of the parent directory named by path or path if path does not contain a parent
    • getFirstDirectoryPart

      public static String getFirstDirectoryPart(String path)
      return the first directory in a path. So c:/a/b/c would return a; b/c/d would return b
      Parameters:
      path - the path
      Returns:
      the first directory in the path
    • getFileExtension

      public static String getFileExtension(String path)
      return the file extention portion of the path
      Returns:
      the portion of the path after the last "." charater. If path is null then an empty String is returned. If there is no "." character in path then an empty String is returned.
    • removeFileExtension

      public static String removeFileExtension(String path)
      Returns a path with the file extension removed. If there is no extension then you get the same string back.
      i.e. ...temp/temp.txt -> .../temp/temp
    • getHostFromUrl

      public static String getHostFromUrl(String url)
    • getHostFromUrl

      public static String getHostFromUrl(String url, boolean prependRmi)
    • pathsEqual

      public static boolean pathsEqual(String path1, String path2)
      check to see if two paths match
      Parameters:
      path1 - first path
      path2 - second path
      Returns:
    • getFilePathFromUrl

      public static String getFilePathFromUrl(String url)
    • getFilePathFromUrl

      public static String getFilePathFromUrl(String url, boolean parseEnvironmentVariable)
    • getVersionStamp

      public static String[] getVersionStamp()
      return the version stamp and the date for the jars
    • getAppVersionProperties

      public static Properties getAppVersionProperties(Class clientAppClass)
    • getJarVersionsFile

      public static InputStream getJarVersionsFile(Class<? extends Object> clientAppClass)
    • getBuildMonthYear

      public static String getBuildMonthYear()
    • getStackTraceString

      public static String getStackTraceString(Throwable t)
      given a Throwable object return a String that contains the StackTrace.
      Parameters:
      t -
      Returns:
      the String representation of the StackTrace
    • toHtmlString

      public static String toHtmlString(String s)
    • toHtmlString

      public static String toHtmlString(String s, int maxLineLength)
      convert a String with newlines in it to an html renderable String
      Parameters:
      s - the String to render
      Returns:
      the html rendererable String
    • writeMultiLineString

      public static void writeMultiLineString(BufferedWriter writer, String tag, String data) throws IOException
      write a String that might contain multiple lines to writer breaking it up on the newline in the String data, prepending each line with tag

      Example:
      if data = this is the \n description
      and tag = Description=

      then the following will get written to the file
      Description=this is the
      Description=description

      Parameters:
      writer - the writer to write to
      tag - the prefix to put at the begining of each line
      data - the data to write.
      Throws:
      IOException
    • localFileCopy

      public static boolean localFileCopy(String srcFilename, String dstFilename)
      Copy a local file (fast)
      Parameters:
      srcFilename - String File name to copy from
      dstFilename - String File name to copy to
      Returns:
      boolean
    • getEnvArray

      public static String[] getEnvArray()
      convert the System.getenv() Map into a String[]
      Returns:
      the
    • listToString

      public static String listToString(List list, String separator)
      convert a list to a String with the separator between each entry
      Parameters:
      list -
      separator -
      Returns:
    • getShortenedPathname

      public static String getShortenedPathname(String pathname, int maxLength)
      Return the pathname (abbreviated pathname if necessary) to be shown in the file menu open item list. A maximum of maxLength characters is used for the pathname because we do not want to make the JMenuItem entry too wide. *
      Parameters:
      pathname - the path to shorten
      maxLength - the maximum length of the pathname before it gets shortened
      Returns:
      the shortened pathname
    • copyFileFromResourcesToTemp

      public static String copyFileFromResourcesToTemp(String resourcePath)
      Copies a resource specified by the input resource path to the "Temp" directory. The resource could be in a Jar file or on disk but it must be in the classpath. Returns the path to the file that was copied. Returns NULL if there was an error.
      Parameters:
      resource - the path to the resource
      Returns:
    • copyFileFromResourcesToDirectory

      public static String copyFileFromResourcesToDirectory(String resourcePath, String destinationDir)
    • cleanMappedDrivePath

      public static String cleanMappedDrivePath(String path)
      given a mapped drive path, change it to a UNC drive path. i.e. Q:\forMark\inundationHangUp.7z is \\RAID01\qa\forMark\inundationHangUp.7z if the path is determined not to be on a mapped drive, then the original path is returned.
      Parameters:
      path -
      Returns:
    • getUncPath

      public static String getUncPath(String drive)
      given a drive letter (Q:) return the UNC path for it.
      Parameters:
      drive -
      Returns: