Class Utils


  • public class Utils
    extends Object
    Provides multiple functions which support HPCCWsClient actions.
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • parseVersionFromWSDLURL

        public static String parseVersionFromWSDLURL​(String wsdlurl)
        Parses the version from WSDLURL.
        Parameters:
        wsdlurl - - url to web service definition
        Returns:
        - version reported as ver_ parameter in url
      • println

        @Deprecated
        public static void println​(PrintStream stream,
                                   String message,
                                   boolean onlyifverbose,
                                   boolean verbosemode)
        Deprecated.
        Println.
        Parameters:
        stream - the stream
        message - the message
        onlyifverbose - the onlyifverbose
        verbosemode - the verbosemode
      • print

        @Deprecated
        public static void print​(PrintStream stream,
                                 String message,
                                 boolean onlyifverbose,
                                 boolean verbosemode)
        Deprecated.
        Prints the.
        Parameters:
        stream - the stream
        message - the message
        onlyifverbose - the onlyifverbose
        verbosemode - the verbosemode
      • log

        public static void log​(String message,
                               Utils.LogLevel logLevel)
        Log.
        Parameters:
        message - the message
        logLevel - the log level
      • parseECLResults

        public static List<List<Object>> parseECLResults​(String results)
        populates results object (List of Object Lists) based on HPCC result set string.
        Parameters:
        results - the results
        Returns:
        the list
      • extactResultSchema

        public static String extactResultSchema​(String results)
        Extact result schema.
        Parameters:
        results - the results
        Returns:
        the string
      • parseOutResultSchema

        public static List<List<Object>> parseOutResultSchema​(String results)
        Parses the out result schema.
        Parameters:
        results - the results
        Returns:
        the list
      • eclResultsToString

        public static String eclResultsToString​(List<List<Object>> resultlist,
                                                String celldelimiter,
                                                String rowdelimiter)
        Serializes results object List of Object Lists to string in table format.
        Parameters:
        resultlist - the resultlist
        celldelimiter - the celldelimiter
        rowdelimiter - the rowdelimiter
        Returns:
        the string
      • writeField

        public void writeField​(OutputStream out,
                               String boundary,
                               String name,
                               char value)
                        throws IOException
        Writes an char field value.
        Parameters:
        out - the out
        boundary - the boundary
        name - the field name (required)
        value - the field value
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • writeField

        public void writeField​(OutputStream out,
                               String boundary,
                               String name,
                               String value)
                        throws IOException
        Writes an string field value. If the value is null, an empty string is sent ("").
        Parameters:
        out - the out
        boundary - the boundary
        name - the field name (required)
        value - the field value
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • writeFile

        public void writeFile​(OutputStream out,
                              String name,
                              String mimeType,
                              File file)
                       throws IOException
        Writes outputstream to file in local file system.
        Parameters:
        out - the out
        name - the name
        mimeType - the mime type
        file - the file
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • writeFile

        public void writeFile​(OutputStream out,
                              String boundary,
                              String name,
                              String mimeType,
                              String fileName,
                              InputStream is)
                       throws IOException
        Writes a input stream's contents. If the input stream is null, a java.lang.IllegalArgumentException will be thrown.
        Parameters:
        out - the out
        boundary - the boundary
        name - the name
        mimeType - the mime type
        fileName - the file name
        is - the is
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • writeFile

        public static void writeFile​(OutputStream out,
                                     String boundary,
                                     String mimeType,
                                     String fileName,
                                     byte[] data)
                              throws IOException
        Writes the given bytes. The bytes are assumed to be the contents of a file, and will be sent as such.
        Parameters:
        out - the out
        boundary - the boundary
        mimeType - the mime type
        fileName - the file name
        data - the data
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • startMulti

        public static void startMulti​(OutputStream out,
                                      String filename,
                                      String boundary,
                                      String mimeType)
                               throws IOException
        Start multi.
        Parameters:
        out - the out
        filename - the filename
        boundary - the boundary
        mimeType - the mime type
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • closeMulti

        public static void closeMulti​(OutputStream out,
                                      String boundary)
                               throws IOException
        Finishes multipart and closes stream.
        Parameters:
        out - the out
        boundary - the boundary
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • createConnection

        public static URLConnection createConnection​(URL url)
                                              throws IOException
        Creates a new java.net.URLConnection object from the specified java.net.URL. This is a convenience method which will set the doInput, doOutput, useCaches and defaultUseCaches fields to the appropriate settings in the correct order.
        Parameters:
        url - the url
        Returns:
        the URL connection
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • createBoundary

        public static String createBoundary()
        creates a Multipart boundry based on current time.
        Returns:
        the string
      • getOperatingSystemType

        public static Utils.OSType getOperatingSystemType()
        detect the operating system from the os.name System property and cache the result
        Returns:
        the operating system type
      • currentOSisLinux

        public static boolean currentOSisLinux()
        Current O sis linux.
        Returns:
        true, if successful
      • findEnumValFromString

        public static <T extends Enum<T>> T findEnumValFromString​(Class<T> enumclass,
                                                                  String strvalue)
        Attempts to map a string value to an enum value of a given enum class. Iterates through all enum values of given enum class, and compares to given string. Returns enum value if it finds match, otherwise throws Exception
        Type Parameters:
        T - the generic type
        Parameters:
        enumclass - reference to target enumaration
        strvalue - string value to be mapped to enum value
        Returns:
        The corresponding enum value if found
        Throws:
        IllegalArgumentException - if strvalue cannot be mapped to given enum
      • dateToUTCString

        public static String dateToUTCString​(Date date)
        Date to UTC string.
        Parameters:
        date - - java date to convert to string
        Returns:
        UTC String for querying esp services in format yyyy-mm-ddThh:MM:ssZ
      • UTCStringToDate

        public static Date UTCStringToDate​(String utc)
                                    throws ParseException
        UTC string to date.
        Parameters:
        utc - - String in yyyy-mm-ddThh:MM:ssZ format
        Returns:
        Date equivalent to string
        Throws:
        ParseException - the parse exception
      • ensureTrailingPathSlash

        public static String ensureTrailingPathSlash​(String path)
        Ensures the given path contains a trailing path delimiter. Does not introduce duplicate trailing path delimiter if one already exists. Defaults to Linux style separator if the given path either contains a Linux style separator, or the path is empty. Strips all trailing white space character
        Parameters:
        path - The path to be postfixed
        Returns:
        original path with proper trailing path delimiter
      • ensureTrailingPathSlash

        public static String ensureTrailingPathSlash​(String path,
                                                     String useLinuxSep)
        Ensures the given path contains a trailing path delimiter. Does not introduce duplicate trailing path delimiter if one already exists. Uses Linux style path separator 'useLinuxSep' == "true", otherwise uses windows style path separator Strips all trailing white space character
        Parameters:
        path - path The path to be postfixed
        useLinuxSep - String, if "true" linux styled path delimiter will be used
        Returns:
        original path with proper trailing path delimiter
      • ensureTrailingPathSlash

        public static String ensureTrailingPathSlash​(String path,
                                                     char slash)
        Ensures the given path contains a trailing path delimiter. Does not introduce duplicate trailing path delimiter if one already exists. Uses provided 'slash' as trailing path delimiter Strips all trailing white space character
        Parameters:
        path - The path to be postfixed
        slash - The character to append
        Returns:
        original path with proper trailing path delimiter
      • trimTrailing

        public static String trimTrailing​(String originalStr)
        Removes trailing whitespace characters from a string.
        Parameters:
        originalStr - the original string from which trailing whitespace should be removed
        Returns:
        a new string with the same characters as the original string, minus any trailing whitespace