public class Util extends Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and 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.
|
public static File createFile(String filename) throws SecurityException, IOException
filename
- the name of file to create.SecurityException
- if the existing file cannot be deleted.IOException
- if an I/O error occurred.public static boolean setOwnerAccessOnly(String file)
setFilePermissions(String, int)
public static boolean setFilePermissions(String file, int mode)
file
- the file to set the permissions of.mode
- the Unix style permissions.public static boolean destroy(String file)
file
- file to removepublic static boolean destroy(File file)
file
- file to removepublic static String getInput(String prompt)
prompt
- the prompt to be displayedString
the input read in (entered after the prompt)public static String getPrivateInput(String prompt)
prompt
- the prompt to be displayedString
the input read in (entered after the prompt)public static String quote(String str)
str
- the string to quotifypublic static String unquote(String str) throws Exception
str
- the string to dequotify.Exception
public static String decode(String s)
String
, each character is examined in turn:
%xy
", where xy is the two-digit
hexadecimal representation of the lower 8-bits of the character.
public static String formatTimeSec(long time)
public static String getLocalHostAddress()
InetAddress
class. In case the lookup
fails, the address 127.0.0.1 is returned.Copyright © 2016. All rights reserved.