java.lang.Object
org.cybergarage.http.HTTPStatus

public class HTTPStatusextends Object
Represents an HTTP status line with version, status code, and reason phrase. This class provides methods to parse and manipulate HTTP status responses, including common status code constants and utility methods.
  • Field Details

    • CONTINUE

      public static final int CONTINUE
      HTTP 100 Continue
      See Also:
    • OK

      public static final int OK
      HTTP 200 OK
      See Also:
    • PARTIAL_CONTENT

      public static final int PARTIAL_CONTENT
      HTTP 206 Partial Content
      See Also:
    • BAD_REQUEST

      public static final int BAD_REQUEST
      HTTP 400 Bad Request
      See Also:
    • NOT_FOUND

      public static final int NOT_FOUND
      HTTP 404 Not Found
      See Also:
    • PRECONDITION_FAILED

      public static final int PRECONDITION_FAILED
      HTTP 412 Precondition Failed
      See Also:
    • INVALID_RANGE

      public static final int INVALID_RANGE
      HTTP 416 Invalid Range
      See Also:
    • INTERNAL_SERVER_ERROR

      public static final int INTERNAL_SERVER_ERROR
      HTTP 500 Internal Server Error
      See Also:
    • version

      private String version
      /////////////////////////////////////////////
    • statusCode

      private int statusCode
      Numeric status of the response.
    • reasonPhrase

      private String reasonPhrase
      Text reason for the status code.
  • Constructor Details

    • HTTPStatus

      public HTTPStatus()
      Creates a new empty HTTPStatus with default values.
    • HTTPStatus

      public HTTPStatus(String ver, int code, String reason)
      Creates a new HTTPStatus with the specified version, code, and reason.
      Parameters:
      ver - the HTTP version (e.g., "HTTP/1.1")
      code - the status code
      reason - the reason phrase
    • HTTPStatus

      public HTTPStatus(String lineStr)
      Creates a new HTTPStatus by parsing a status line string. The line should be in the format "HTTP/1.1 200 OK".
      Parameters:
      lineStr - the status line to parse
  • Method Details

    • code2String

      public static final String code2String(int code)
      Converts an HTTP status code to its corresponding reason phrase string.

      This method provides the standard HTTP reason phrases for common status codes. If the status code is not recognized, an empty string is returned.

      Parameters:
      code - the HTTP status code to convert
      Returns:
      the corresponding reason phrase, or empty string if code is not recognized
    • setVersion

      public void setVersion(String value)
      Sets the HTTP version.
      Parameters:
      value - the HTTP version (e.g., "HTTP/1.1")
    • setStatusCode

      public void setStatusCode(int value)
      Sets the status code.
      Parameters:
      value - the status code
    • setReasonPhrase

      public void setReasonPhrase(String value)
      Sets the reason phrase.
      Parameters:
      value - the reason phrase
    • getVersion

      public String getVersion()
      Gets the HTTP version.
      Returns:
      the HTTP version
    • getStatusCode

      public int getStatusCode()
      Gets the status code.
      Returns:
      the status code
    • getReasonPhrase

      public String getReasonPhrase()
      Gets the reason phrase.
      Returns:
      the reason phrase
    • isSuccessful

      public static final boolean isSuccessful(int statCode)
      Checks if the given status code represents a successful response (2xx range).
      Parameters:
      statCode - the status code to check
      Returns:
      true if the status code is in the 200-299 range
    • isSuccessful

      public boolean isSuccessful()
      Checks if this status represents a successful response (2xx range).
      Returns:
      true if the status code is in the 200-299 range
    • set

      public void set(String lineStr)
      Parses a status line string and sets the version, code, and reason phrase. The line should be in the format "HTTP/1.1 200 OK".
      Parameters:
      lineStr - the status line to parse