public class

Net

extends Object
implements INet
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.net.Net

Class Overview

A network object used to download from and upload to http/https URLs, with socks and http proxy support.

Summary

Public Constructors
Net()
Create a standard Net object, using global proxy settings set using setGlobalProxyInformation(NetProxyInfo).
Net(Net net0)
Copy constructor.
Public Methods
static long convertHttpDateToEpoch(String dateString)
An HTTP Date.
long downloadBinary(File dstfile, String url, Map<String, String> urlParams, Map<String, String> serverHeaders, IProgressCallback progressCallback)
Download a binary and dump it to disk.
INet duplicate()
Duplicate this object to perform safe parameter update.
int getConnectTimeout()
static NetProxyInfo getGlobalProxyInformation()
NetProxyInfo getProxyInformation()
int getReadTimeout()
SecureSocketInfo getSecureSocketInfo()
String getUserAgent()
int getWriteTimeout()
static boolean isConnectedToInternet()
Determine if the system appears to be connected to the Internet.
static boolean isConnectedToNetwork()
Determine if the system offers at least one active non-loopback network interface.
String 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.
String post(String url, Map<String, String> urlParams, Map<String, String> bodyParams)
@return
String 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 the multipart/form-data encoding.
String postMultipart(String url, Map<String, String> formParams, Map<String, FormFileEntry> formFiles)
@return
String query(String url, Map<String, String> urlParams, Map<String, String> serverHeaders)
Perform an http GET request.
String query(String url)
Perform an http GET request.
String query(String url, Map<String, String> parameters)
@return
byte[] queryBinary(String url, Map<String, String> parameters)
@return
byte[] queryBinary(String url)
Perform an http GET request.
byte[] queryBinary(String url, Map<String, String> urlParams, Map<String, String> serverHeaders, IProgressCallback progressCallback)
Perform an http GET request.
byte[] queryBinary(String url, Map<String, String> urlParams, Map<String, String> serverHeaders)
Perform an http GET request.
void setConnectTimeout(int timeout)
static void setGlobalProxyInformation(NetProxyInfo proxyinfo)
void setReadTimeout(int timeout)
void setSecureSocketInfo(SecureSocketInfo info)
void setUserAgent(String userAgent)
void setWriteTimeout(int timeout)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.pnfsoftware.jeb.util.net.INet

Public Constructors

public Net ()

Create a standard Net object, using global proxy settings set using setGlobalProxyInformation(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.

public Net (Net net0)

Copy constructor.

Parameters
net0 an existing net object

Public Methods

public static long convertHttpDateToEpoch (String dateString)

An HTTP Date.

Returns
  • epoch in ms; 0 on error (that is, Jan 1 1970)

public long downloadBinary (File dstfile, String url, Map<String, String> urlParams, Map<String, String> serverHeaders, IProgressCallback progressCallback)

Download a binary and dump it to disk. Similar to queryBinary(String, Map, Map, IProgressCallback), but the downloaded data is not stored and returned, therefore making this method more suitable to download Large files.

Parameters
progressCallback optional listener
Returns
  • the server response
Throws
IOException

public INet duplicate ()

Duplicate this object to perform safe parameter update.

Returns
  • a new net object with the same properties as this object (timeouts, user-agent, etc.)

public int getConnectTimeout ()

public static NetProxyInfo getGlobalProxyInformation ()

Returns
  • optional proxy info object

public NetProxyInfo getProxyInformation ()

public int getReadTimeout ()

public SecureSocketInfo getSecureSocketInfo ()

public String getUserAgent ()

public int getWriteTimeout ()

public static boolean isConnectedToInternet ()

Determine if the system appears to be connected to the Internet.

Returns
  • true or false

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

public String 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.

Parameters
url url with optional parameters
urlParams optional additional url parameters
bodyParams request content parameters
Returns
  • the server response
Throws
IOException

public String post (String url, Map<String, String> urlParams, Map<String, String> bodyParams)

@return

Throws
IOException

public String 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 the multipart/form-data encoding.

Parameters
url url with optional parameters
formParams optional request content parameters
formFiles optional request content files
Returns
  • the server response
Throws
IOException

public String postMultipart (String url, Map<String, String> formParams, Map<String, FormFileEntry> formFiles)

@return

Throws
IOException

public String query (String url, Map<String, String> urlParams, Map<String, String> serverHeaders)

Perform an http GET request.

Parameters
url url with optional parameters
urlParams optional additional url parameters
Returns
  • the server response
Throws
IOException

public String query (String url)

Perform an http GET request.

Parameters
url url with optional parameters
Returns
  • the server response
Throws
IOException

public String query (String url, Map<String, String> parameters)

@return

Throws
IOException

public byte[] queryBinary (String url, Map<String, String> parameters)

@return

Throws
IOException

public byte[] queryBinary (String url)

Perform an http GET request.

Parameters
url url with optional parameters
Returns
  • the server response
Throws
IOException

public byte[] queryBinary (String url, Map<String, String> urlParams, Map<String, String> serverHeaders, IProgressCallback progressCallback)

Perform an http GET request.

Parameters
progressCallback optional listener
Returns
  • the server response
Throws
IOException

public byte[] queryBinary (String url, Map<String, String> urlParams, Map<String, String> serverHeaders)

Perform an http GET request.

Parameters
url url with optional parameters
urlParams optional additional url parameters
Returns
  • the server response
Throws
IOException

public void setConnectTimeout (int timeout)

public static void setGlobalProxyInformation (NetProxyInfo proxyinfo)

public void setReadTimeout (int timeout)

public void setSecureSocketInfo (SecureSocketInfo info)

public void setUserAgent (String userAgent)

public void setWriteTimeout (int timeout)