@Exported public class Utilities extends Object
| Modifier and Type | Field and Description | 
|---|---|
| static String | msgbodyUse this to locate the body portion
 of a returned getPOP3Messages() element | 
| static String | productFor finding out the IPS product name | 
| Modifier | Constructor and Description | 
|---|---|
| protected  | Utilities() | 
| Modifier and Type | Method and Description | 
|---|---|
| static boolean | appendFile(String fname,
          byte[] bytes,
          int size)Appends to a file to disk. | 
| static boolean | appendFile(String fname,
          String str)Appends to a file to disk. | 
| static long | availableDisk(String pathDir) | 
| static Calendar | calendarFromJDBCString(String s)Returns a calendar object from JDBC date/time. | 
| static Path | createTempFile(boolean bManageDelete)Method to create a temporary file | 
| static boolean | cryptoEnabled()Checks if encryption is enabled. | 
| static String | deBabble(String s)Replaces %20,%22,%19,%3c,%3e,%26 in input string with
 the characters they represent. | 
| static String | decryptString(String s)Decrypts a string with the default key. | 
| static String | decryptString(String s,
             byte[] key)Decrypts a string with the supplied key. | 
| static boolean | deleteFile(String fname)Deletes a file from disk. | 
| static Vector | directoryList(String path,
             String filter,
             boolean recurse,
             int maxcount)Returns a vector of filenames given a
 path and a filter. | 
| static Vector | directoryList(String path,
             String filter,
             boolean recurse,
             int maxcount,
             COM.FutureTense.Interfaces.IDirectoryObserver ido)Returns a vector of filenames given a
 path and a filter. | 
| static int | emptyFolder(String path,
           boolean bDelete)Delete a folder (optional) and all the contents
 within, recursively. | 
| static int | emptyfolder(String path,
           String pattern)Delete all the files which match the pattern from the
 specified directory tree, recursively. | 
| static String | encryptPlatformString(String s)Encrypts a string with the default key. | 
| static String | encryptPlatformString(String s,
                     byte[] key)Encrypts a string with the supplied key. | 
| static String | encryptString(String s)Encrypts a string with the default key. | 
| static String | encryptString(String s,
             byte[] key)Encrypts a string with the supplied key. | 
| static boolean | ensureFolder(Path path)Make sure a path exists, creating sub-folders as needed. | 
| static boolean | ensureFolder(String path)Make sure a path exists, creating
 subfolders as needed | 
| static boolean | equals(String createddate,
      String updateddate)Sometimes java get this from database
 
 2014-05-01 10:39:17.333 
 2014-05-01 10:39:17.332
 
 but they are exactly the same in database | 
| static Vector | fetchPOP3Messages(String host,
                 String user,
                 char[] password,
                 boolean bRemove)Retrieves a vector of messages from a POP3 server;
 default connection timeout is 190 seconds. | 
| static Vector | fetchPOP3Messages(String host,
                 String user,
                 char[] password,
                 boolean bRemove,
                 int ctimeout)Retrieves a vector of messages from a POP3 server;
 specify the connection timeout on checking for new mail. | 
| static boolean | fileExists(String name)Does a verification of a file existing on disk. | 
| static String | fileFromSpec(String spec)Returns a file from a file specification. | 
| static boolean | fileLockLoadOK()Check to see if the file lock native
 library loaded successfully. | 
| static String | fileName(String folder,
        String fname)Creates a full path including file name, given a folder and file name. | 
| static String | generateUUID() | 
| static String | genID()Deprecated. 
 use ICS.genID(boolean) instead | 
| static String | genID(ICS icsThread)Deprecated. 
 use ICS.genID(boolean) instead | 
| static String | getBLOBDir(String seed)Generate hash-based directory based on given seed. | 
| static Comparator<String> | getCaseInSensitiveStringComparator()Returns a comparator for string objects, which compares strings in case insensitive way. | 
| static char[] | getCharArray(String value)Converts String to char[] | 
| static String | getNameNoTrailingNumber(String name)Returns normalized name after removing the trailing comma number from name. | 
| static FTValList | getParams(String in)Build a vallist of parameters given input
 in the form of a=b and c=d | 
| static void | getParams(String sInput,
         Map map,
         boolean bDecode)Build a map of parameters given input in the form of a=b and c=d | 
| static Vector | getPOP3Messages(String host,
               String user,
               String password,
               boolean bRemove)Deprecated. 
 fetchPOP3Messages | 
| static Vector | getPOP3Messages(String host,
               String user,
               String password,
               boolean bRemove,
               int ctimeout)Deprecated. 
 use fetchPOP3Messages | 
| static String | getWebRoot() | 
| static boolean | goodString(char[] s) | 
| static boolean | goodString(String s)Return if a string is empty or null | 
| static String | handleOSCharacters(String input)Handles characters reserved by supported OS. | 
| static boolean | isAllowedHeader(String headerStr)The method is used to check whether the passed header is valid or not. | 
| static int | isFile(String p)Verify a file | 
| static int | isFolder(String p)Verify a folder | 
| static boolean | isText(String sContentType)Method to determine whether sContentType is a text mime-type
 
 Note: the standard is evolving
 
 Reference: 1. | 
| static boolean | isValidEmail(String email)Check if the email is a valid email, this enforces the same check that is enforced 
 by the UI pages. | 
| static boolean | itemIsInList(Vector l,
            String s,
            boolean c)Determines if a given string is in a vector. | 
| static String | jdbcDateFromCal(Calendar c)Returns a JDBC formatted date from a
 calendar object. | 
| static String | jdbcTimeFrom(Calendar cal)Returns a JDBC formatted time from a
 calendar object. | 
| static String | keysFromMap(Map map)Return a string of keys from the Map | 
| static boolean | lockFile(String file)Lock a file name for exclusive use by this
 thread. | 
| static boolean | osIgnoreFileCase()Return if the server OS has case specific
 versus case preserve file system naming. | 
| static String | osSafeSpec(String spec)Returns a filespec where the "/" or "\" characters
 have been replaced by the system specific
 paths. | 
| static String | pathFromSpec(String spec)Returns a path from a file specification. | 
| static byte[] | readByteFile(String spec)Reads in the file indicated by the passed
 file path,
 and returns the bytes. | 
| static byte[] | readByteURL(String spec)Reads the passed URL, and returns its bytes. | 
| static byte[] | readByteURL(String spec,
           boolean secure)Reads the passed URL, and returns its bytes. | 
| static String | readFile(Path spec)Reads in the file indicated by the passed file path, and returns its contents. | 
| static String | readFile(String spec)Reads in the file indicated by the passed
 file path, and returns its contents. | 
| static boolean | readFile(String spec,
        OutputStream os)Reads in the file indicated by the passed
 file path, and writes the bytes to the stream. | 
| static String | readFile(String spec,
        String sEncoding)Reads in the file indicated by the passed
 file path, and returns its contents. | 
| static String | readURL(String url)Reads the passed URL, and returns its contents. | 
| static String | readURL(String url,
       boolean secure)Reads the passed URL, and returns its contents. | 
| static String | replaceAll(String source,
          String what,
          String with)Replaces a strings contents (all occurrences) with
 specified values. | 
| static boolean | sendMail(String from,
        String[] to,
        String sub,
        String replyto,
        String messagestr,
        String server,
        StringBuffer err)Sends an SMTP mail | 
| static boolean | sendMail(String from,
        String[] to,
        String sub,
        String replyto,
        String messagestr,
        String server,
        String contenttype,
        StringBuffer err)Deprecated. 
 use sendMail which includes charset instead | 
| static boolean | sendMail(String from,
        String[] to,
        String sub,
        String replyto,
        String messagestr,
        String server,
        String contenttype,
        String charset,
        StringBuffer err)Sends an SMTP mail | 
| static boolean | sendMail(String from,
        String to,
        String sub,
        String replyto,
        String messagestr,
        String server,
        StringBuffer err)Sends an SMTP mail message. | 
| static boolean | sendMail(String from,
        String to,
        String sub,
        String replyto,
        String messagestr,
        String server,
        String contenttype,
        StringBuffer err)Deprecated. 
 use sendMail which includes charset instead | 
| static boolean | sendMail(String from,
        String to,
        String sub,
        String replyto,
        String messagestr,
        String server,
        String contenttype,
        String charset,
        StringBuffer err)Sends an SMTP mail message. | 
| static Vector | sortWords(Vector words)Sort a list of strings, longest to shortest | 
| static Vector | sortWordsAlpha(Vector words)Sort a list of strings alphanumerically | 
| static String | sqlDate(Calendar cal)Returns a string formatted as JDBC date/time
 from a calendar object. | 
| static String | stringFromList(List list)Method to convert a collection into a comma separated list | 
| static String | stringFromValList(Map map)Create a url-like set of name/values
 from a map ie x=y and a=b and c=d | 
| static String | stringFromValList(Map map,
                 boolean bEncode)Create a url-like set of name/values
 from a map ie x=y and a=b and c=d | 
| static String | tempFolder() | 
| static boolean | unlockFile(String file)Unlock a file name from exclusive use by this
 thread | 
| static int | unzip2(String basedir,
      InputStream in) | 
| static int | unzipFile(String zip,
         String folder)Unzips a file into a folder. | 
| static boolean | validateZip(String zip)Validates a zip file's zip integrity. | 
| static Vector | words(String str,
     int sep)Parses a string into a vector of words. | 
| static Vector | words(String cmd,
     String sep)Parses a string into a vector of words. | 
| static boolean | writeFile(String fname,
         byte[] bytes,
         int len)Writes a file to disk, given an OS specific path and the contents of the file. | 
| static boolean | writeFile(String fname,
         String str)Writes a file to disk, given an OS specific path and the contents of the file. | 
| static boolean | writeFile2(String fname,
          byte[] bytes,
          int len) | 
| static boolean | zip(Map map,
   String file)Takes for each entry in the map makes a zip entry, and then
 creates the zip in a location specified by sOutputFile. | 
| static boolean | zip2(Map<String,Path> files,
    OutputStream out) | 
| static boolean | zipDirectory(String zipfile,
            String dirname,
            boolean recursive,
            String files)Takes for each entry in the map makes a zip entry, and then
 creates the zip in a location specified by sOutputFile. | 
public static String product
public static String msgbody
public static String getWebRoot()
public static final String osSafeSpec(String spec)
spec - The input file specification.public static final String pathFromSpec(String spec)
spec - file specificationUtilities.fileFromSpec(String)public static final String fileFromSpec(String spec)
spec - file specificationUtilities.pathFromSpec(String)public static final Path createTempFile(boolean bManageDelete) throws IOException
bManageDelete - true to indicate that call will not delete the fileIOException - on errorpublic static final String readFile(String spec, String sEncoding)
spec - The path and file name of the file to read.sEncoding - The character encoding of the file datapublic static final String readFile(String spec)
spec - The path and file name of the file to read.public static final String readFile(Path spec)
spec - The path of the file to readpublic static final byte[] readByteFile(String spec)
spec - The path and file name of the file to read.public static final boolean fileExists(String name)
name - The path and file name of the file to verify.public static final boolean readFile(String spec, OutputStream os) throws IOException
spec - The path and file name of the file to read.
 Stream may throw an exception.os - An OutputStreamIOException - on errorpublic static final String readURL(String url)
url - The URL to read, that is, "http://www.futuretense.com/".public static final byte[] readByteURL(String spec)
spec - The URL to read, that is, "http://www.futuretense.com/".public static final String readURL(String url, boolean secure)
url - The URL to read, that is, "http://www.futuretense.com/".secure - If true will validate the content using ESAPI validatorpublic static final byte[] readByteURL(String spec, boolean secure)
spec - The URL to read, that is, "http://www.futuretense.com/".secure - If true will validate the content using ESAPI validatorpublic static final String fileName(String folder, String fname)
folder - The folder for the file.fname - The name of the file.public static final boolean writeFile(String fname, String str)
fname - The path and name of the file.str - The data to write to the file.public static final int unzipFile(String zip, String folder)
zip - The path and name of the file to unzip.folder - The folder to unzip the file into.public static boolean zip2(Map<String,Path> files, OutputStream out) throws Exception
Exceptionpublic static int unzip2(String basedir, InputStream in) throws IOException
IOExceptionpublic static final boolean zip(Map map, String file) throws Exception
map - Entries to zip up in the form String, blobfile - The full path to target zip file.Exception - on errorpublic static final boolean zipDirectory(String zipfile, String dirname, boolean recursive, String files) throws Exception
zipfile - Target filedirname - Directory to ziprecursive - Whether to recurse into subdirectoriesfiles - File selector such as (*.*, *.class, etc)IOException - on errorExceptionpublic static final boolean validateZip(String zip)
zip - The path/name of the file to unzip.public static final boolean writeFile(String fname, byte[] bytes, int len)
fname - The path and name of the file.bytes - The byte array to write to the file.len - The number of bytes to write.public static final boolean writeFile2(String fname, byte[] bytes, int len)
public static final int isFolder(String p)
p - folder pathpublic static final int isFile(String p)
p - file namepublic static final boolean deleteFile(String fname)
fname - The path and file name of the file to delete.public static final int emptyFolder(String path, boolean bDelete)
path - namebDelete - boolean - delete folder toopublic static final boolean ensureFolder(String path)
path - namepublic static final boolean ensureFolder(Path path)
path - public static final int emptyfolder(String path, String pattern)
path - namepattern - file wildcard pattern to matchpublic static final boolean appendFile(String fname, String str)
fname - The path and file name of the file to delete.str - The file data to append, in string form.public static final boolean appendFile(String fname, byte[] bytes, int size)
fname - The path and file name of the file to delete.bytes - The file data to append, in a byte array.size - The number of bits to append.public static final String deBabble(String s)
s - string to convertpublic static final String replaceAll(String source, String what, String with)
source - The source string. NULL or empty returns samewhat - What to replace. NULL or empty returns source.with - The replacement values (may be null to erase).public static final String genID(ICS icsThread)
icsThread - An interface object used to synchronize
 this number across VM's and/or the cluster.Utilities.genID(), 
ICS.genID(boolean)public static final String genID()
Utilities.genID(ICS), 
ICS.genID(boolean)public static final Vector words(String str, int sep)
str - String of words to parse.sep - The separator character.public static final Vector sortWords(Vector words)
words - Vector of stringspublic static final Vector sortWordsAlpha(Vector words)
words - Vector of stringspublic static final Vector words(String cmd, String sep)
cmd - String of words to parse.sep - String of separating characters.public static final boolean goodString(String s)
s - input stringpublic static final boolean goodString(char[] s)
public static final String stringFromList(List list)
list - a listpublic static FTValList getParams(String in)
in - The input string containing the parameters.public static void getParams(String sInput, Map map, boolean bDecode)
sInput - The input string containing the parameters.map - The output map of key/value pairsbDecode - true to indicate that decoding is desiredpublic static final String jdbcDateFromCal(Calendar c)
c - Calendar with date.Utilpublic static final String jdbcTimeFrom(Calendar cal)
cal - Calendar with date.Utilpublic static final String sqlDate(Calendar cal)
cal - Calendar with date and time.Utilpublic static Calendar calendarFromJDBCString(String s)
s - String in the form of YYYY-MM-DD HH24:MI:SSUtilpublic static final boolean itemIsInList(Vector l, String s, boolean c)
l - The Vector list of strings.s - The String item to find.c - boolean True for caseless check, false otherwise.public static Vector directoryList(String path, String filter, boolean recurse, int maxcount)
path - OS specific path.filter - File filter, as in *.bat, *.*.  Not
 all OS specific filter characters are supported.recurse - A "true" value specifies to
 look for matching files (based on filter) in
 subdirectories of the supplied path.maxcount - Specifies the maximum number
 of files that will be returned in the vector. Note
 that it is possible to generate outofmemory exceptions
 by specifying a very large number.public static Vector directoryList(String path, String filter, boolean recurse, int maxcount, COM.FutureTense.Interfaces.IDirectoryObserver ido)
path - OS specific path.filter - File filter, as in *.bat, *.*.  Not
 all OS specific filter characters are supported.recurse - A "true" value specifies to
 look for matching files (based on filter) in
 subdirectories of the supplied path.maxcount - Specifies the maximum number
 of files that will be returned in the vector. Note
 that it is possible to generate outofmemory exceptions
 by specifying a very large number.ido - an IDirectoryObserverpublic static final boolean sendMail(String from, String to, String sub, String replyto, String messagestr, String server, StringBuffer err)
from - The FROM field.to - One or more email addresses, comma seperated.sub - The SUBJECT field.replyto - The REPLY TO field.messagestr - The message BODY.server - The name of the mail server.err - Error string, set on failure.public static final boolean sendMail(String from, String to, String sub, String replyto, String messagestr, String server, String contenttype, StringBuffer err)
from - The FROM field.to - One or more email addresses, comma seperated.sub - The SUBJECT field.replyto - The REPLY TO field.messagestr - The message BODY.server - The name of the mail server.contenttype - The content-type of the message bodyerr - Error string, set on failure.public static final boolean sendMail(String from, String to, String sub, String replyto, String messagestr, String server, String contenttype, String charset, StringBuffer err)
from - The FROM field.to - One or more email addresses, comma seperated.sub - The SUBJECT field.replyto - The REPLY TO field.messagestr - The message BODY.server - The name of the mail server.contenttype - The content-type of the message bodycharset - The character set of the message subjecterr - Error string, set on failure.public static final boolean sendMail(String from, String[] to, String sub, String replyto, String messagestr, String server, StringBuffer err)
from - The FROM field.to - An array of email addresses.sub - The SUBJECT field.replyto - The REPLY TO field.messagestr - The message BODY.server - The name of the mail server.err - Error string, set on failure.public static final boolean sendMail(String from, String[] to, String sub, String replyto, String messagestr, String server, String contenttype, StringBuffer err)
from - The FROM field.to - An array of email addresses.sub - The SUBJECT field.replyto - The REPLY TO field.messagestr - The message BODY.server - The name of the mail server.contenttype - The content-type of the message bodyerr - Error string, set on failure.public static final boolean sendMail(String from, String[] to, String sub, String replyto, String messagestr, String server, String contenttype, String charset, StringBuffer err)
from - The FROM field.to - An array of email addresses.sub - The SUBJECT field.replyto - The REPLY TO field.messagestr - The message BODY.server - The name of the mail server.contenttype - The content-type of the message bodycharset - The character set of the message subjecterr - Error string, set on failure.public static Vector getPOP3Messages(String host, String user, String password, boolean bRemove)
host - Host server.user - User account.password - User password.bRemove - Set to "true" to remove the messages from the server
 after get.public static Vector fetchPOP3Messages(String host, String user, char[] password, boolean bRemove)
host - Host server.user - User account.password - User password.bRemove - Set to "true" to remove the messages from the server
 after get.public static Vector getPOP3Messages(String host, String user, String password, boolean bRemove, int ctimeout)
host - Host server.user - User account.password - User password.bRemove - Set to "true" to remove the messages from the server
 after get.ctimeout - timeout (seconds) to fail during first connectpublic static Vector fetchPOP3Messages(String host, String user, char[] password, boolean bRemove, int ctimeout)
host - Host server.user - User account.password - User password.bRemove - Set to "true" to remove the messages from the server
 after get.ctimeout - timeout (seconds) to fail during first connectpublic static final boolean cryptoEnabled()
public static final String encryptPlatformString(String s)
s - The string to encrypt. String is converted to bytes using default platform encoding before encrypting it.public static final String encryptPlatformString(String s, byte[] key)
s - The string to encrypt. String is converted to bytes using default platform encoding before encrypting it.key - a key supplied for encrypting a stringpublic static final String encryptString(String s)
s - The string to encrypt. This method limits the input string to ascii characters. If non-ascii characters
 are used in the input, the decrypt() utility will not return original value.public static final String encryptString(String s, byte[] key)
s - The string to encrypt. This method limits the input string to ascii characters. If non-ascii characters
 are used in the input, the decrypt() utility will not return original value.key - a key supplied for encrypting a stringpublic static String decryptString(String s)
s - The string to decrypt.public static String decryptString(String s, byte[] key)
key - a key supplied for encrypting a strings - The string to decrypt.public static boolean lockFile(String file)
file - filename to lockpublic static boolean unlockFile(String file)
file - filename to unlockpublic static boolean osIgnoreFileCase()
public static String stringFromValList(Map map)
map - Map to compress to stringUtilities.stringFromValList(Map, boolean)public static String stringFromValList(Map map, boolean bEncode)
map - Map to compress to stringbEncode - true to encode keys and valuesUtilities.stringFromValList(Map)public static String keysFromMap(Map map)
map - input Mappublic static boolean fileLockLoadOK()
public static String getBLOBDir(String seed)
seed - Value based on which the folder structure will be generated. It is suggested
             to use the filename as seed, but not necessary.public static String getNameNoTrailingNumber(String name)
name - a namepublic static String generateUUID()
public static final boolean isAllowedHeader(String headerStr)
headerStr - header stringpublic static final String tempFolder()
public static String handleOSCharacters(String input)
input - string on which the manipulation is to be performed.public static final Comparator<String> getCaseInSensitiveStringComparator()
public static final boolean isValidEmail(String email)
email - the email addresspublic static final boolean isText(String sContentType)
sContentType - content typepublic static final boolean equals(String createddate, String updateddate)
createddate - a date from databaseupdateddate - a date from databasepublic static long availableDisk(String pathDir) throws IOException
IOExceptionpublic static char[] getCharArray(String value)
value -