Package rma.util
Class RMAIO
java.lang.Object
rma.util.RMAIO
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doublearrayMax(double[] array) return the maximum value for the array arraystatic intarrayMax(int[] array) return the maximum value for the array arraystatic doublearrayMin(double[] array) return the minimum value for the array arraystatic intarrayMin(int[] array) return the minimum value for the array arraystatic StringBufferstatic StringBufferstatic StringcleanMappedDrivePath(String path) given a mapped drive path, change it to a UNC drive path.static Stringgiven 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.static booleancompareArrays(double[] array1, double[] array2, double precision) Returns an int representing the comparison of val to compareTo using precision.static intcompareTo(double val, double compareTo, double precision) Returns an int representing the comparison of val to compareTo using precision.static StringconcatPath(String path, String newPart) add a new file path part to a file path.static StringcopyFileFromResourcesToDirectory(String resourcePath, String destinationDir) static StringcopyFileFromResourcesToTemp(String resourcePath) Copies a resource specified by the input resource path to the "Temp" directory.static voidcopyHashToVector(Hashtable ht, Vector vec) Places the reference *keys* of the java.util.Hashtable into the java.util.Vector.static intcountCharacters(String s, char charToCount) count the number of times character charToCount occurs in String sstatic voidendianSwap(short[] array) static StringBufferfillString(int bufSize, char c) static intfindPrecision(double val) find the precision of a numberstatic StringformatDate(long time) static StringformatDate(long time, String format) static StringformatDate(long time, String format, String strTimezone) static StringformatDate(long time, String format, TimeZone timezone) static StringformatDate(long time, TimeZone timezone) static voidfout(BufferedWriter out, String txt) static PropertiesgetAppVersionProperties(Class clientAppClass) static Stringstatic longgetCheckSum(File file) static Stringget the local computer name.static StringgetDirectoryFromPath(String path) return the parent directory portion of the pathstatic String[]convert the System.getenv() Map into a String[]static StringgetFileExtension(String path) return the file extention portion of the pathstatic StringgetFileFromPath(String path) return the file name portion of the path with the extension (if it has one)static StringgetFileNameNoExtension(String path) return the file name portion of the path with no extension.static StringgetFilePathFromUrl(String url) static StringgetFilePathFromUrl(String url, boolean parseEnvironmentVariable) static StringgetFirstDirectoryPart(String path) return the first directory in a path.static StringgetHostFromUrl(String url) static StringgetHostFromUrl(String url, boolean prependRmi) static Stringreturn the String url that has the IP address in it instead of a hostnamestatic InputStreamgetJarVersionsFile(Class<? extends Object> clientAppClass) static intreturn the constant that represents our current JAVA versionstatic intgetNumChars(String s, char c) return the number of times character c appears in String sstatic intreturn the constant that represents our current OS typestatic Stringstatic StringParses line and returns the portion after delim.static StringgetPathNoExtension(String path) return the path with no file extension.static StringgetPropertyFilePath(String filename) static StringgetRelativePath(String basePath, String fullPath) Returns a path that is relative to the base path.static StringgetRelativePath(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.static Stringstatic StringgetShortenedPathname(String pathname, int maxLength) Return the pathname (abbreviated pathname if necessary) to be shown in the file menu open item list.static Stringgiven a Throwable object return a String that contains the StackTrace.static Stringstatic StringParses the expression TYPEPARAM and returns the string and returns the TYPE. static StringgetUncPath(String drive) given a drive letter (Q:) return the UNC path for it.static String[]return the version stamp and the date for the jarsstatic intindexOf(int[] array, int key) Scan the int arrayarrayfor presence of the intkey.static booleanisFullPath(String path) check to see if the path is a full or relative pathstatic booleanisRelativePathTo(String basePath, String fullPath) Returns a boolean flag that indicates if the fullpath is contained in the base path.static StringBufferleftJustify(int bufsize, String inputStr) Takes a string a puts it is a StringBuffer where the given string is left justifiedstatic StringBufferleftJustify(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 fillstatic StringlistToString(List list, String separator) convert a list to a String with the separator between each entrystatic booleanlocalFileCopy(String srcFilename, String dstFilename) Copy a local file (fast)static StringmakeAbsolutePath(String basePath, String relPath) static booleanparseBoolean(String value, boolean defaultValue) Parses the argument string value into a boolean through case insensitive matching on the following.static ColorparseColorString(String colorString) return theColorspecified bycolorStringstatic longReturns a UTC long representing the java.util.Date ms long value that corresponds to the argument date String.static longReturns a UTC long representing the java.util.Date ms long value that corresponds to the argument date String and the argument time zone.static doubleparseDouble(ParamDouble dbl) static doubleparseDouble(ParamDouble dbl, double def) static doubleparseDouble(Object dbl) static doubleparseDouble(Object dbl, double def) Writen by SJN.static doubleparseDouble(String str) static doubleparseDouble(String str, double def) static floatparseFloat(Object flt) static floatparseFloat(Object obj, float def) static floatparseFloat(String str) static floatparseFloat(String flt, float def) static intstatic intParses a string and returns the int value of that string.static intParses the given string and converts to an integer.static intparseIntervalName(String intvName) static longstatic longParses a string and returns the long value of that string.static longParses the given string and converts to an long.static StringparsePathEnvVars(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.static StringparsePathName(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.static ColorparseRGBString(String rgbStr) static VectorparseStringWithQuotes(String line) Parses a string, like string.split() does, but respects quoted portions of the string, treating them like a complete part.static booleanpathsEqual(String path1, String path2) check to see if two paths matchstatic voidstatic voidstatic voidstatic intpostOkCancelWarning(Component parent, String msg) static intpostOkCancelWarning(Component parent, String msg, String title) static voidpostWarning(Component parent, String msg) static voidpostWarning(Component parent, String msg, String title) static intpostYesNoCancelWarning(Component parent, String msg) static intpostYesNoCancelWarning(Component parent, String msg, String title) static intpostYesNoMessage(Component parent, String msg, String title) static intpostYesNoWarning(Component parent, String msg) static intpostYesNoWarning(Component parent, String msg, String title) static StringremoveChar(String s, char c) static StringremoveCharAt(String s, int pos) static StringremoveFileExtension(String path) Returns a path with the file extension removed.static Stringremove non-printable characters from the Stringstatic StringremoveTrailingChars(String s, char c) static Stringreplace oldChars in str with newCharsstatic StringBufferrightJustify(int bufsize, String inputStr) Takes a string a puts it is a StringBuffer where the given string is right justifiesstatic StringBufferrightJustify2(int bufsize, String inputStr) Takes a string a puts it is a StringBuffer where the given string is right justifiesstatic doubleround(double dbl, int precision) Takes as input a double value to round and the precision to round it to.static StringsetPrecision(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 stringstatic StringsetPrecision2(double dbl, int precision) static StringsetPrecision3(double dbl) figure out the precision of a number and return it.static StringBuffersprintf(int bufSize, double num) static StringBuffersprintf(int bufSize, int num) static StringBufferstatic Stringreturns a new String that is a substring of string.static StringsubtractUndef(double param1, double param2, int precission) Returns a string representation of a double with a given precissionstatic Stringstatic StringtoHtmlString(String s, int maxLineLength) convert a String with newlines in it to an html renderable Stringstatic StringtoString(double val) static StringtoString(float val) static StringtoString(int val) static StringtoTable(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(""); }static StringtoTable(float val) static StringtoTable(int val) static ObjecttoTableObj(Double val) static ObjecttoTableObj(Float val) static ObjecttoTableObj(Integer val) static Stringtrim off all characters trimChar from String sstatic Stringstatic voidstatic StringtrimToFilename(String filepath) static StringtrimTrailing(String s, char trailingChar) trim off all trailing characters trailingChar from String sstatic StringuserNameFromUserId(String userId) static StringuserNameToFileName(String userName) static voidwriteMultiLineString(BufferedWriter writer, String tag, String data) 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
-
Field Details
-
ID_SEPARATOR
- See Also:
-
separator
- See Also:
-
invalidFileNameChars
public static char[] invalidFileNameChars -
intervalNames
parse time strings and return int seconds -
intervalValues
public static int[] intervalValues
-
-
Method Details
-
getRGBString
-
getIPUrl
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
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 parseddefaultValue- returned if the string value does not match- Returns:
- true or false
-
parseRGBString
-
parseColorString
return theColorspecified bycolorString- Parameters:
colorString- either a RGB value r,g,b or a color name "blue"- Returns:
- the
Colorspecified bycolorStringg
-
color2String
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
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 comparisonfullPath- - 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
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 comparisonfullPath- - the full file path that will be turned into the relative path- Returns:
-
getType
Parses the expression TYPEPARAM and returns the string and returns the TYPE. If the DELIM does not exist the original line is returned -
getParam
-
getParam
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 fortrim- method should trim before returning.- Returns:
- portion of line which occurs after delim.
-
parseInt
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 parsedefaultVal- the default value to use if the parse failes.
-
parseInt
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
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 parsedefaultVal- the default value to use if the parse failes.
-
parseLong
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
-
parseFloat
-
parseFloat
-
parseDouble
-
parseDouble
-
toString
-
toString
-
toString
-
toTable
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
-
toTable
-
toTableObj
-
toTableObj
-
toTableObj
-
fout
-
sprintf
-
sprintf
-
sprintf
-
copyHashToVector
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
-
parseDouble
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
-
parseDouble
-
parseLong
-
parseInt
-
parseFloat
-
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 roundprecision- to round to.
-
setPrecision
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
-
setPrecision3
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
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
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
-
formatDate
-
formatDate
-
formatDate
-
formatDate
-
trimToFilename
-
substring
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 stringExamplessubstring("hamburger", "b", true) returns "ham" substring("hamburger", "bur", false) return "ger"
- Returns:
- a new String, or an empty String if subString or string
is
nullor string doesn't contain subString - See Also:
-
fillString
-
center
-
center
-
rightJustify2
Takes a string a puts it is a StringBuffer where the given string is right justifies -
rightJustify
Takes a string a puts it is a StringBuffer where the given string is right justifies -
leftJustify
Takes a string a puts it is a StringBuffer where the given string is left justified -
leftJustify
Takes a string a puts it is a StringBuffer where the given string is left justified fill with the character fill -
subtractUndef
Returns a string representation of a double with a given precission -
getSystemHomeDirectory
-
getPropertyFilePath
-
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
-
postError
-
postError
-
postWarning
-
postWarning
-
postYesNoWarning
-
postYesNoWarning
-
postYesNoMessage
-
postYesNoCancelWarning
-
postYesNoCancelWarning
-
postOkCancelWarning
-
postOkCancelWarning
-
parsePathName
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
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
-
userNameFromUserId
-
userNameToFileName
-
replace
replace oldChars in str with newChars- Returns:
- string with replaced chars
-
removeNonPrintable
remove non-printable characters from the String- Parameters:
s- the String to remove the non-printable characters from- Returns:
- See Also:
-
removeChar
-
removeTrailingChars
-
countCharacters
count the number of times character charToCount occurs in String s- Parameters:
s- the String to count chars incharToCount- the character to look for- Returns:
- the number of times charToCount occurs in s
-
trimTrailing
trim off all trailing characters trailingChar from String s- Parameters:
s- the String to trim trailingChar fromtrailingChar- the char to remove- Returns:
- the new String
-
trim
trim off all characters trimChar from String s- Parameters:
s- the String to trim trailingChar fromtrimChar- the char to remove- Returns:
- the new String
-
trim
-
removeCharAt
-
getNumChars
return the number of times character c appears in String s -
parseStringWithQuotes
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
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
-
endianSwap
public static void endianSwap(short[] array) -
makeAbsolutePath
-
isFullPath
check to see if the path is a full or relative path -
getCheckSum
-
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_INTif the array isnull.Integer.MAX_VALUEif 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_INTif the array isnull.Integer.MIN_VALUEif 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_INTif the array isnull.Integer.MAX_VALUEif 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_INTif the array isnull.Integer.MIN_VALUEif the array has a length of 0.
-
indexOf
public static int indexOf(int[] array, int key) Scan the int arrayarrayfor presence of the intkey. 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
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 pathnewPart- the new part to add to the path- Returns:
- the path with the newPart added to it.
-
getFileNameNoExtension
return the file name portion of the path with no extension.- Parameters:
path- the path- Returns:
- the file name portion.
-
getPathNoExtension
return the path with no file extension.- Parameters:
path- the path- Returns:
- the path with no file extension
-
getFileFromPath
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
separatorcharacter. if the path isnullanullis returned. if noseparatorcharacters are found then the entire path is returned.
-
getDirectoryFromPath
return the parent directory portion of the pathThe 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
separatorcharacter.- 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
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
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
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
-
getHostFromUrl
-
pathsEqual
check to see if two paths match- Parameters:
path1- first pathpath2- second path- Returns:
-
getFilePathFromUrl
-
getFilePathFromUrl
-
getVersionStamp
return the version stamp and the date for the jars -
getAppVersionProperties
-
getJarVersionsFile
-
getBuildMonthYear
-
getStackTraceString
given a Throwable object return a String that contains the StackTrace.- Parameters:
t-- Returns:
- the String representation of the StackTrace
-
toHtmlString
-
toHtmlString
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 tagExample:
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 totag- the prefix to put at the begining of each linedata- the data to write.- Throws:
IOException
-
localFileCopy
Copy a local file (fast)- Parameters:
srcFilename- String File name to copy fromdstFilename- String File name to copy to- Returns:
- boolean
-
getEnvArray
convert the System.getenv() Map into a String[]- Returns:
- the
-
listToString
convert a list to a String with the separator between each entry- Parameters:
list-separator-- Returns:
-
getShortenedPathname
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 shortenmaxLength- the maximum length of the pathname before it gets shortened- Returns:
- the shortened pathname
-
copyFileFromResourcesToTemp
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
-
cleanMappedDrivePath
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
given a drive letter (Q:) return the UNC path for it.- Parameters:
drive-- Returns:
-