Java Utililty Methods HTTP Port Find

List of utility methods to do HTTP Port Find

Description

The list of methods to do HTTP Port Find are organized into topic(s).

Method

booleanping(String domain, int port)
ping
boolean result = false;
Socket socket = null;
try {
    socket = new Socket(domain, port);
    result = true;
} catch (UnknownHostException e) {
} catch (IOException e) {
} finally {
...
BooleanpingServer(String host, Integer port)
ping Server
String timeStamp = "";
Socket socket = null;
BufferedReader br = null;
try {
    socket = new Socket(host, port);
    br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    timeStamp = br.readLine();
    socket.close();
...
intrandomAvailablePort()
random Available Port
try {
    ServerSocket socket = new ServerSocket(0);
    int port = socket.getLocalPort();
    socket.close();
    return port;
} catch (IOException e) {
    throw new RuntimeException(e);
intrandomFreePort()
Returns a random free port and marks that port as taken.
int port = 0;
boolean portAvailable = true;
;
do {
    port = randomPort();
    portAvailable = available(port);
} while (!portAvailable);
return port;
...
intrandomFreePort()
random Free Port
int port = 0;
do {
    port = randomPort();
    try {
        ServerSocket sock = new ServerSocket(port);
        sock.close();
    } catch (IOException ex) {
        port = 0;
...
intrandomFreePort()
Returns a random free port and marks that port as taken.
int port = 0;
do {
    port = randomPort();
    if (takenRandomPorts.contains(port)) {
        port = 0;
        continue;
    takenRandomPorts.add(port);
...
Stringread(String host, int port)
read
return read(host, port, null);
ListreadHttpContent(String domain, String resource, int port)
read Http Content
Socket socket = null;
try {
    socket = new Socket(domain, port);
    PrintWriter out = new PrintWriter(socket.getOutputStream());
    StringBuilder send = new StringBuilder();
    send.append("GET " + resource + " HTTP/1.0").append("\n");
    send.append("Accept: text/html").append("\n");
    send.append("\n");
...
voidreplace(final String host, final int port, final String user, final String program, final String relation, final String dataset, final String format)
Replace the contents of a dataset.
URL url = getDatasetUrl(host, port, user, program, relation, format);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestMethod("PUT");
byte[] payload = dataset.getBytes("UTF-8");
conn.setFixedLengthStreamingMode(payload.length);
try {
...
InetSocketAddressresolve(final String desc, final int defaultPort)
Parse and resolve an address string, looking up the IP address.
final InetSocketAddress addr = parse(desc, defaultPort);
if (addr.getAddress() != null && addr.getAddress().isAnyLocalAddress()) {
    return addr;
try {
    final InetAddress host = InetAddress.getByName(addr.getHostName());
    return new InetSocketAddress(host, addr.getPort());
} catch (UnknownHostException e) {
...