Package org.globus.util

# Class Util

java.lang.Object
org.globus.util.Util

public class Util extends Object

## Constructor Summary

Constructors
Constructor
Description
`Util()`

## Method Summary

Modifier and Type
Method
Description
`static File`
`createFile(String filename)`
Attempts to create a new file in an atomic way.
`static String`
`decode(String s)`
The function decodes URL-encoded strings into a regular string.
`static boolean`
`destroy(File file)`
Overwrites the contents of the file with a random string and then deletes the file.
`static boolean`
`destroy(String file)`
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`
`getInput(String prompt)`
Displays a prompt and then reads in the input from System.in.
`static String`
`getLocalHostAddress()`
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`
`quote(String str)`
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`
`unquote(String str)`
Dequotifies a specified string.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Util

public Util()

## Method Details

### createFile

public static File createFile(String filename) throws SecurityException, IOException
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

public static boolean setOwnerAccessOnly(String file)
Sets permissions on a given file to be only accessible by the current user.

See Also:
  - `setFilePermissions(String, int)`

### setFilePermissions

public static boolean setFilePermissions(String file, int mode)
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

public static boolean destroy(String file)
Overwrites the contents of the file with a random string and then deletes the file.

Parameters:
  `file` - file to remove

### destroy

public static boolean destroy(File file)
Overwrites the contents of the file with a random string and then deletes the file.

Parameters:
  `file` - file to remove

### getInput

public static String getInput(String prompt)
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

public static String getPrivateInput(String prompt)
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

public static String quote(String str)
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

public static String unquote(String str) throws Exception
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

public static String decode(String s)
The function decodes URL-encoded strings into a regular string. This function is mostly copied from the Java source code. To convert to a `String`, 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.

### formatTimeSec

public static String formatTimeSec(long time)
Generates string representation of given time specified as long. The format is: [days][,][h][,][min][,][sec]

### getLocalHostAddress

public static String 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 the `InetAddress` class. In case the lookup fails, the address 127.0.0.1 is returned.

Returns:
  local ip address