Package org.hpccsystems.ws.client.utils
Class Utils
- java.lang.Object
-
- org.hpccsystems.ws.client.utils.Utils
-
public class Utils extends Object
Provides multiple functions which support HPCCWsClient actions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Utils.HPCCEnvOSCode
HPCC Environment OS codes as defined in /HPCC-Platform/common/environment/environment.hppstatic class
Utils.LogLevel
static class
Utils.OSType
-
Field Summary
Fields Modifier and Type Field Description protected static Utils.OSType
detectedOS
static String
ISO8601_FORMAT
static char
LINUX_SEP
static char
WIN_SEP
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
closeMulti(OutputStream out, String boundary)
Finishes multipart and closes stream.static String
createBoundary()
creates a Multipart boundry based on current time.static URLConnection
createConnection(URL url)
Creates a newjava.net.URLConnection
object from the specifiedjava.net.URL
.static boolean
currentOSisLinux()
Current O sis linux.static String
dateToUTCString(Date date)
Date to UTC string.static String
eclResultsToString(List<List<Object>> resultlist, String celldelimiter, String rowdelimiter)
Serializes results object List of Object Lists to string in table format.static String
ensureTrailingPathSlash(String path)
Ensures the given path contains a trailing path delimiter.static String
ensureTrailingPathSlash(String path, char slash)
Ensures the given path contains a trailing path delimiter.static String
ensureTrailingPathSlash(String path, String useLinuxSep)
Ensures the given path contains a trailing path delimiter.static String
extactResultSchema(String results)
Extact result schema.static <T extends Enum<T>>
TfindEnumValFromString(Class<T> enumclass, String strvalue)
Attempts to map a string value to an enum value of a given enum class.static Utils.OSType
getOperatingSystemType()
detect the operating system from the os.name System property and cache the resultstatic void
log(String message, Utils.LogLevel logLevel)
Log.static DocumentBuilder
newSafeXMLDocBuilder()
static DocumentBuilderFactory
newSafeXMLDocBuilderFactory()
static List<List<Object>>
parseECLResults(String results)
populates results object (List of Object Lists) based on HPCC result set string.static List<List<Object>>
parseOutResultSchema(String results)
Parses the out result schema.static String
parseVersionFromWSDLURL(String wsdlurl)
Parses the version from WSDLURL.static void
print(PrintStream stream, String message, boolean onlyifverbose, boolean verbosemode)
Deprecated.static void
println(PrintStream stream, String message, boolean onlyifverbose, boolean verbosemode)
Deprecated.static void
startMulti(OutputStream out, String filename, String boundary, String mimeType)
Start multi.static String
trimTrailing(String originalStr)
Removes trailing whitespace characters from a string.static Date
UTCStringToDate(String utc)
UTC string to date.void
writeField(OutputStream out, String boundary, String name, char value)
Writes an char field value.void
writeField(OutputStream out, String boundary, String name, String value)
Writes an string field value.void
writeFile(OutputStream out, String name, String mimeType, File file)
Writes outputstream to file in local file system.static void
writeFile(OutputStream out, String boundary, String mimeType, String fileName, byte[] data)
Writes the given bytes.void
writeFile(OutputStream out, String boundary, String name, String mimeType, String fileName, InputStream is)
Writes a input stream's contents.
-
-
-
Field Detail
-
LINUX_SEP
public static final char LINUX_SEP
- See Also:
- Constant Field Values
-
WIN_SEP
public static final char WIN_SEP
- See Also:
- Constant Field Values
-
ISO8601_FORMAT
public static final String ISO8601_FORMAT
- See Also:
- Constant Field Values
-
detectedOS
protected static Utils.OSType detectedOS
-
-
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 streammessage
- the messageonlyifverbose
- the onlyifverboseverbosemode
- the verbosemode
-
print
@Deprecated public static void print(PrintStream stream, String message, boolean onlyifverbose, boolean verbosemode)
Deprecated.Prints the.- Parameters:
stream
- the streammessage
- the messageonlyifverbose
- the onlyifverboseverbosemode
- the verbosemode
-
log
public static void log(String message, Utils.LogLevel logLevel)
Log.- Parameters:
message
- the messagelogLevel
- 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 resultlistcelldelimiter
- the celldelimiterrowdelimiter
- 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 outboundary
- the boundaryname
- 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 outboundary
- the boundaryname
- 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 outname
- the namemimeType
- the mime typefile
- 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, ajava.lang.IllegalArgumentException
will be thrown.- Parameters:
out
- the outboundary
- the boundaryname
- the namemimeType
- the mime typefileName
- the file nameis
- 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 outboundary
- the boundarymimeType
- the mime typefileName
- the file namedata
- 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 outfilename
- the filenameboundary
- the boundarymimeType
- 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 outboundary
- the boundary- Throws:
IOException
- Signals that an I/O exception has occurred.
-
createConnection
public static URLConnection createConnection(URL url) throws IOException
Creates a newjava.net.URLConnection
object from the specifiedjava.net.URL
. This is a convenience method which will set thedoInput
,doOutput
,useCaches
anddefaultUseCaches
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 enumarationstrvalue
- 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
-
newSafeXMLDocBuilderFactory
public static DocumentBuilderFactory newSafeXMLDocBuilderFactory() throws ParserConfigurationException
- Throws:
ParserConfigurationException
-
newSafeXMLDocBuilder
public static DocumentBuilder newSafeXMLDocBuilder() throws ParserConfigurationException, XPathExpressionException
-
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 postfixeduseLinuxSep
- 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 postfixedslash
- 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
-
-