Class HecFileUtil

java.lang.Object
hec.heclib.util.HecFileUtil

public final class HecFileUtil extends Object
Utility methods for file operations, string parsing, and formatting used within the hec.heclib package. Methods extracted from rma.util.RMAIO to remove the dependency on rma.util for the heclib sub-project.
  • Field Details

  • Method Details

    • getType

      public static String getType(String line, String delim)
      Parses a line of the form TYPE<DELIM>PARAM and returns the TYPE portion. If the delimiter does not exist, the original line (trimmed) is returned.
    • getParam

      public static String getParam(String line, String delim)
      Parses a line and returns the portion after the delimiter. If the line does not contain the delimiter, an empty string is returned.
    • getParam

      public static String getParam(String line, String delim, boolean trim)
      Parses a line and returns the portion after the delimiter. If the line does not contain the delimiter, an empty string is returned.
      Parameters:
      line - a String of the form TYPE<DELIM>PARAM
      delim - the delimiting substring to search for
      trim - whether to trim the result before returning
      Returns:
      the portion of line which occurs after delim
    • parseInt

      public static int parseInt(String str, int defaultVal)
      Parses a string and returns the int value. If an exception occurs, the default value is returned.
    • parseInt

      public static int parseInt(String str)
      Parses a string and returns the int value. If an exception occurs, UNDEF_INT is returned.
    • parseDouble

      public static double parseDouble(String str, double def)
      Parses a string and returns the double value. If an exception occurs, the default value is returned.
    • parseDouble

      public static double parseDouble(String str)
      Parses a string and returns the double value. If an exception occurs, UNDEF_DOUBLE is returned.
    • leftJustify

      public static StringBuffer leftJustify(int bufsize, String inputStr)
      Left-justifies a string in a StringBuffer of the given size, padding with spaces on the left.
    • leftJustify

      public static StringBuffer leftJustify(int bufsize, String inputStr, char fill)
      Left-justifies a string in a StringBuffer of the given size, padding with the fill character on the left.
    • getSystemHomeDirectory

      public static String getSystemHomeDirectory()
      Returns the CWMS_HOME system property.
    • getExtension

      public static String getExtension(File f)
      Returns the lowercase extension of the filename or null
    • getFileFromPath

      public static String getFileFromPath(String path)
      Returns the filename portion of a path (after the last separator).
    • parsePathName

      public static String parsePathName(String pathName)
      Given a path with an embedded $CWMS_HOME, returns 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, returns the path with the $APPDATA or APPDATA env var replaced with the value of the env var.
    • trimSeparators

      public static void trimSeparators(StringBuffer sb)