All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.darwinsys.net.NetResult Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package com.darwinsys.net;

import java.net.HttpURLConnection;

/** Encode the Result of a Network operation, typically over HTTP */
public class NetResult {
    int status;
    T payload;
    final int HTTP_REDIRECTS = 
		HttpURLConnection.HTTP_MULT_CHOICE; // lowest 3xx error def'n

    public int getStatus() {
        return status;
    }

	public void setStatus(int status) {
		this.status = status;
	}

    public T getPayload() {
        return payload;
    }

	public void setPayload(T payload) {
		this.payload = payload;
	}

    public boolean isSuccess() {
        return status >= HttpURLConnection.HTTP_OK && status < HTTP_REDIRECTS;
    }

    @Override
    public String toString() {
        return "Result(" + (isSuccess()? "Success" : "Failure") + " (" + status + ") " + payload;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy