public class SoftwareServerUtility extends Object
Constructor and Description |
---|
SoftwareServerUtility() |
Modifier and Type | Method and Description |
---|---|
static String |
addAuthentication(String url,
String authentication)
Add authentication to a URL.
|
static void |
deleteStoreFiles(String parent_folder,
int session,
String logfilename)
Delete temporary files for a session under parent_folder
session temporary files' names start with "sessionid_"
session log is ".session_" + session + ".log"
|
static void |
downloadFile(String path,
String name,
String url)
download file from given url
|
static String |
executeAndWait(String command,
int max_runtime)
Execute the given command.
|
static String |
executeAndWait(String command,
int max_runtime,
boolean HANDLE_OUTPUT,
boolean SHOW_OUTPUT)
Execute the given command.
|
static boolean |
existsURL_bak(String url)
Deprecated.
|
static boolean |
existsURL(String url)
Check if the specified URL exists.
|
static long |
getFileSize(String filename)
Get the size of a local or remote file.
|
static String |
getFileSizeHR(String filename)
Get the size of a local or remote file in a human readable form.
|
static String |
getTimeStamp()
Get the current date and time (useful for logs, is thread safe).
|
static String |
humanReadableBytes(long bytes)
Get bytes in human readable form.
|
static void |
main(String[] args)
A main for debug purposes.
|
static String |
postFile(String url,
String filename)
Post a file to a URL.
|
static String |
postFile(String url,
String filename,
String type,
String auth)
Post a file to a URL.
|
static void |
print(String string,
String filename)
Append a string to a file.
|
static void |
println(String string,
String filename)
Append a line to a file.
|
static String |
readURL(String url)
Read the contents of the specified URL and store it in a string.
|
static String |
readURL(String url,
String type)
Read the contents of the specified URL and store it in a string.
|
static String |
removeCredentials(String url_str)
Remove credentials in the url string, like username:passwd
|
static void |
setDefaultAuthentication(String authentication)
Set default authentication for HTTP requests.
|
static void |
unzip(String path,
String filename)
Unzip a zip file into the given path.
|
static void |
zip(String output,
String file)
Zip a file or directory.
|
static void |
zip(String output,
Vector<String> files)
Zip a given set of files.
|
static void |
zip(ZipOutputStream outs,
String path,
String filename)
Add a file to the given zip file output stream.
|
public static void downloadFile(String path, String name, String url)
path
- path of downloaded filename
- filename of the downloaded fileurl
- url of filepublic static String removeCredentials(String url_str)
url_str
- url stringpublic static void deleteStoreFiles(String parent_folder, int session, String logfilename)
parent_folder
- folder contains session generated temporary filessession
- session idlogfilename
- associated log filename@Deprecated public static boolean existsURL_bak(String url)
url
- the URL to checkpublic static boolean existsURL(String url)
url
- the URL to checkpublic static String readURL(String url, String type)
url
- the URL to readtype
- the accepted content typepublic static String readURL(String url)
url
- the URL to readpublic static String postFile(String url, String filename, String type, String auth)
url
- the URL to post tofilename
- the name of the file to posttype
- the accepted content typeauth
- the authentication to use (e.g. user:password, null)public static String postFile(String url, String filename)
url
- the URL to post tofilename
- the name of the file to postpublic static long getFileSize(String filename)
filename
- the file name or URLpublic static String humanReadableBytes(long bytes)
bytes
- the number of bytespublic static String getFileSizeHR(String filename)
filename
- the file name or URLpublic static String executeAndWait(String command, int max_runtime, boolean HANDLE_OUTPUT, boolean SHOW_OUTPUT)
command
- the commandmax_runtime
- the maximum allowed time to run (in milli-seconds, -1 indicates forever)HANDLE_OUTPUT
- true if the process output should be handledSHOW_OUTPUT
- true if the process output should be shownpublic static String executeAndWait(String command, int max_runtime)
command
- the commandmax_runtime
- the maximum allowed time to run (in milli-seconds, -1 indicates forever)public static String addAuthentication(String url, String authentication)
url
- a URLauthentication
- the "username:password"public static void setDefaultAuthentication(String authentication)
authentication
- the "username:password"public static void print(String string, String filename)
string
- the text to append to the filefilename
- the file to append topublic static void println(String string, String filename)
string
- the line to append to the filefilename
- the file to append topublic static String getTimeStamp()
public static void unzip(String path, String filename)
path
- the path to unzip tofilename
- the name of the zip filepublic static void zip(String output, String file)
output
- the output zip filefiles
- a filepublic static void zip(String output, Vector<String> files)
output
- the output zip filefiles
- a vector of filespublic static void zip(ZipOutputStream outs, String path, String filename)
outs
- the zip file output streampath
- the path to the file (minus the portion of the path that should be stored in the zip file)filename
- the name of the file to add (plus the portion of the path that should be stored in the zip file)public static void main(String[] args)
args
- the command line argumentsCopyright © 2018. All rights reserved.