Package com.pnfsoftware.jeb.util.net
Class Net
java.lang.Object
com.pnfsoftware.jeb.util.net.Net
- All Implemented Interfaces:
INet
A network object used to download from and upload to http/https URLs, with socks and http proxy
support.
-
Constructor Summary
ConstructorsConstructorDescriptionNet()Create a standard Net object, using global proxy settings set usingsetGlobalProxyInformation(NetProxyInfo).Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionokhttp3.OkHttpClientbuildClient(String url) okhttp3.OkHttpClientbuildClient(String url, IProgressCallback progressCallback) okhttp3.OkHttpClientbuildClient(String url, IProgressCallback progressCallback, int[] timeouts) static longconvertHttpDateToEpoch(String dateString) An HTTP Date.longdownloadBinary(File dstfile, String url, Map<String, String> urlParams, Map<String, String> serverHeaders, IProgressCallback progressCallback) Download a binary and dump it to disk.Duplicate this object to perform safe parameter update.intstatic NetProxyInfointintstatic booleanDetermine if the system appears to be connected to the Internet.static booleanDetermine if the system offers at least one active non-loopback network interface.post(String url, Map<String, String> urlParams, Map<String, String> bodyParams, Map<String, String> serverHeaders) Perform an http POST request to send a simple form.postMultipart(String url, Map<String, String> formParams, Map<String, FormFileEntry> formFiles) postMultipart(String url, Map<String, String> formParams, Map<String, FormFileEntry> formFiles, Map<String, String> serverHeaders) Perform an http POST request to send a form using themultipart/form-dataencoding.Perform an http GET request.Perform an http GET request.byte[]queryBinary(String url) Perform an http GET request.byte[]queryBinary(String url, Map<String, String> parameters) byte[]Perform an http GET request.byte[]queryBinary(String url, Map<String, String> urlParams, Map<String, String> serverHeaders, IProgressCallback progressCallback) Perform an http GET request.voidsetConnectTimeout(int timeout) static voidsetGlobalProxyInformation(NetProxyInfo proxyinfo) voidsetReadTimeout(int timeout) voidvoidsetUserAgent(String userAgent) voidsetWriteTimeout(int timeout)
-
Constructor Details
-
Net
public Net()Create a standard Net object, using global proxy settings set usingsetGlobalProxyInformation(NetProxyInfo). The user-agent is set to "PNF Software UP"; the timeouts are set to 60 seconds for connect, 30 seconds for read, 120 seconds for write; redirects are followed. -
Net
Copy constructor.- Parameters:
net0- an existing net object
-
-
Method Details
-
setGlobalProxyInformation
-
getGlobalProxyInformation
- Returns:
- optional proxy info object
-
duplicate
Description copied from interface:INetDuplicate this object to perform safe parameter update. -
getProxyInformation
-
setUserAgent
- Specified by:
setUserAgentin interfaceINet- Parameters:
userAgent- a user-agent
-
getUserAgent
- Specified by:
getUserAgentin interfaceINet- Returns:
- the user-agent
-
setConnectTimeout
public void setConnectTimeout(int timeout) - Specified by:
setConnectTimeoutin interfaceINet- Parameters:
timeout- in milliseconds
-
getConnectTimeout
public int getConnectTimeout()- Specified by:
getConnectTimeoutin interfaceINet- Returns:
- timeout in milliseconds
-
setReadTimeout
public void setReadTimeout(int timeout) - Specified by:
setReadTimeoutin interfaceINet- Parameters:
timeout- timeout in milliseconds
-
getReadTimeout
public int getReadTimeout()- Specified by:
getReadTimeoutin interfaceINet- Returns:
- timeout in milliseconds
-
setWriteTimeout
public void setWriteTimeout(int timeout) - Specified by:
setWriteTimeoutin interfaceINet- Parameters:
timeout- timeout in milliseconds
-
getWriteTimeout
public int getWriteTimeout()- Specified by:
getWriteTimeoutin interfaceINet- Returns:
- timeout in milliseconds
-
getSecureSocketInfo
- Specified by:
getSecureSocketInfoin interfaceINet- Returns:
-
setSecureSocketInfo
- Specified by:
setSecureSocketInfoin interfaceINet
-
buildClient
- Parameters:
url- optional but recommended if a proxy is in place- Returns:
-
buildClient
- Parameters:
url- optional but recommended if a proxy is in placeprogressCallback- optional- Returns:
-
buildClient
public okhttp3.OkHttpClient buildClient(String url, IProgressCallback progressCallback, int[] timeouts) - Parameters:
url- optional but recommended if a proxy is in placeprogressCallback- optionaltimeouts- optional (if null, the class timeouts are used); else, a 3-value array of timeouts in ms: connect, read, write- Returns:
-
post
public String post(String url, Map<String, String> urlParams, Map<String, throws IOExceptionString> bodyParams, Map<String, String> serverHeaders) Description copied from interface:INetPerform an http POST request to send a simple form.- Specified by:
postin interfaceINet- Parameters:
url- url with optional parametersurlParams- optional additional url parametersbodyParams- request content parameters- Returns:
- the server response
- Throws:
IOException- on error
-
post
public String post(String url, Map<String, String> urlParams, Map<String, throws IOExceptionString> bodyParams) - Specified by:
postin interfaceINet- Returns:
- Throws:
IOException
-
postMultipart
public String postMultipart(String url, Map<String, String> formParams, Map<String, throws IOExceptionFormFileEntry> formFiles, Map<String, String> serverHeaders) Description copied from interface:INetPerform an http POST request to send a form using themultipart/form-dataencoding.- Specified by:
postMultipartin interfaceINet- Parameters:
url- url with optional parametersformParams- optional request content parametersformFiles- optional request content files- Returns:
- the server response
- Throws:
IOException- on error
-
postMultipart
public String postMultipart(String url, Map<String, String> formParams, Map<String, throws IOExceptionFormFileEntry> formFiles) - Specified by:
postMultipartin interfaceINet- Returns:
- Throws:
IOException
-
query
public String query(String url, Map<String, String> urlParams, Map<String, throws IOExceptionString> serverHeaders) Description copied from interface:INetPerform an http GET request.- Specified by:
queryin interfaceINet- Parameters:
url- url with optional parametersurlParams- optional additional url parameters- Returns:
- the server response
- Throws:
IOException- on error
-
query
- Specified by:
queryin interfaceINet- Returns:
- Throws:
IOException
-
query
Description copied from interface:INetPerform an http GET request.- Specified by:
queryin interfaceINet- Parameters:
url- url with optional parameters- Returns:
- the server response
- Throws:
IOException- on error
-
queryBinary
public byte[] queryBinary(String url, Map<String, String> urlParams, Map<String, throws IOExceptionString> serverHeaders, IProgressCallback progressCallback) Description copied from interface:INetPerform an http GET request.- Specified by:
queryBinaryin interfaceINetprogressCallback- optional listener- Returns:
- the server response
- Throws:
IOException
-
queryBinary
public byte[] queryBinary(String url, Map<String, String> urlParams, Map<String, throws IOExceptionString> serverHeaders) Description copied from interface:INetPerform an http GET request.- Specified by:
queryBinaryin interfaceINet- Parameters:
url- url with optional parametersurlParams- optional additional url parameters- Returns:
- the server response
- Throws:
IOException- on error
-
queryBinary
- Specified by:
queryBinaryin interfaceINet- Returns:
- Throws:
IOException
-
queryBinary
Description copied from interface:INetPerform an http GET request.- Specified by:
queryBinaryin interfaceINet- Parameters:
url- url with optional parameters- Returns:
- the server response
- Throws:
IOException- on error
-
downloadBinary
public long downloadBinary(File dstfile, String url, Map<String, String> urlParams, Map<String, throws IOExceptionString> serverHeaders, IProgressCallback progressCallback) Description copied from interface:INetDownload a binary and dump it to disk. Similar toINet.queryBinary(String, Map, Map, IProgressCallback), but the downloaded data is not stored and returned, therefore making this method more suitable to download Large files.- Specified by:
downloadBinaryin interfaceINetprogressCallback- optional listener- Returns:
- the server response
- Throws:
IOException
-
convertHttpDateToEpoch
An HTTP Date.- Parameters:
dateString-- Returns:
- epoch in ms; 0 on error (that is, Jan 1 1970)
-
isConnectedToNetwork
public static boolean isConnectedToNetwork()Determine if the system offers at least one active non-loopback network interface. Careful! This cannot be used to reliably find out if the system has an Internet connection.- Returns:
- true or false
-
isConnectedToInternet
public static boolean isConnectedToInternet()Determine if the system appears to be connected to the Internet.- Returns:
- true or false
-