Package org.globus.util
Class Util
java.lang.Object
org.globus.util.Util
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A helper thread to mask private user input. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic File
createFile
(String filename) Attempts to create a new file in an atomic way.static String
The function decodes URL-encoded strings into a regular string.static boolean
Overwrites the contents of the file with a random string and then deletes the file.static boolean
Overwrites the contents of the file with a random string and then deletes the file.static String
formatTimeSec
(long time) Generates string representation of given time specified as long.static String
Displays a prompt and then reads in the input from System.in.static String
Returns the ip address of the local machine.static String
getPrivateInput
(String prompt) Displays a prompt and then reads in private input from System.in.static String
Quotifies a specified string.static boolean
setFilePermissions
(String file, int mode) Sets permissions on a given file.static boolean
setOwnerAccessOnly
(String file) Sets permissions on a given file to be only accessible by the current user.static String
Dequotifies a specified string.
-
Field Details
-
CHMOD
- See Also:
-
DMSG
- See Also:
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
createFile
Attempts to create a new file in an atomic way. If the file already exists, it if first deleted.- Parameters:
filename
- the name of file to create.- Returns:
- the created file.
- Throws:
SecurityException
- if the existing file cannot be deleted.IOException
- if an I/O error occurred.
-
setOwnerAccessOnly
Sets permissions on a given file to be only accessible by the current user.- See Also:
-
setFilePermissions
Sets permissions on a given file. The permissions are set using the chmod command and will only work on Linux/Unix machines. Chmod command must be in the path.
Note: This function executes an external program; thus, its behavior is influenced by environment variables such as the caller's PATH and the environment variables that control dynamic loading. Care should be used if calling this function from a program that will be run as a Unix setuid program, or in any other manner in which the owner of the Unix process does not completely control its runtime environment.- Parameters:
file
- the file to set the permissions of.mode
- the Unix style permissions.- Returns:
- true, if change was successful, otherwise false. It can return false, in many instances, e.g. when file does not exits, when chmod is not found, or other error occurs.
-
destroy
Overwrites the contents of the file with a random string and then deletes the file.- Parameters:
file
- file to remove
-
destroy
Overwrites the contents of the file with a random string and then deletes the file.- Parameters:
file
- file to remove
-
getInput
Displays a prompt and then reads in the input from System.in.- Parameters:
prompt
- the prompt to be displayed- Returns:
String
the input read in (entered after the prompt)
-
getPrivateInput
Displays a prompt and then reads in private input from System.in. Characters typed by the user are replaced with a space on the screen.- Parameters:
prompt
- the prompt to be displayed- Returns:
String
the input read in (entered after the prompt)
-
quote
Quotifies a specified string. The entire string is encompassed by double quotes and each " is replaced with \", \ is replaced with \\.- Parameters:
str
- the string to quotify- Returns:
- quotified and escaped string
-
unquote
Dequotifies a specified string. The quotes are removed and each \" is replaced with " and each \\ is replaced with \.- Parameters:
str
- the string to dequotify.- Returns:
- unquotified string.
- Throws:
Exception
-
decode
The function decodes URL-encoded strings into a regular string. This function is mostly copied from the Java source code. To convert to aString
, each character is examined in turn:- The remaining characters are represented by 3-character
strings which begin with the percent sign,
"
%xy
", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character.
- The remaining characters are represented by 3-character
strings which begin with the percent sign,
"
-
formatTimeSec
Generates string representation of given time specified as long. The format is: [days][,][h][,][min][,][sec] -
getLocalHostAddress
Returns the ip address of the local machine. If the 'ip' system property is defined it is returned, otherwise, the local ip address is lookup using theInetAddress
class. In case the lookup fails, the address 127.0.0.1 is returned.- Returns:
- local ip address
-