org.cybergarage.http

## Class HTTPStatus

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

-     public class HTTPStatus
      extends 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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BAD_REQUEST`
    `static int` | `CONTINUE`
    `static int` | `INTERNAL_SERVER_ERROR`
    `static int` | `INVALID_RANGE`
    `static int` | `NOT_FOUND`
    `static int` | `OK`
    `static int` | `PARTIAL_CONTENT`
    `static int` | `PRECONDITION_FAILED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HTTPStatus()` Creates a new empty HTTPStatus with default values.
    `HTTPStatus(String lineStr)` Creates a new HTTPStatus by parsing a status line string.
    `HTTPStatus(String ver, int code, String reason)` Creates a new HTTPStatus with the specified version, code, and reason.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `code2String(int code)` Converts an HTTP status code to its corresponding reason phrase string.
    `String` | `getReasonPhrase()` Gets the reason phrase.
    `int` | `getStatusCode()` Gets the status code.
    `String` | `getVersion()` Gets the HTTP version.
    `boolean` | `isSuccessful()` Checks if this status represents a successful response (2xx range).
    `static boolean` | `isSuccessful(int statCode)` Checks if the given status code represents a successful response (2xx range).
    `void` | `set(String lineStr)` Parses a status line string and sets the version, code, and reason phrase.
    `void` | `setReasonPhrase(String value)` Sets the reason phrase.
    `void` | `setStatusCode(int value)` Sets the status code.
    `void` | `setVersion(String value)` Sets the HTTP version.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BAD_REQUEST

          public static final int BAD_REQUEST

      See Also:
        Constant Field Values

    - #### CONTINUE

          public static final int CONTINUE

      See Also:
        Constant Field Values

    - #### INTERNAL_SERVER_ERROR

          public static final int INTERNAL_SERVER_ERROR

      See Also:
        Constant Field Values

    - #### INVALID_RANGE

          public static final int INVALID_RANGE

      See Also:
        Constant Field Values

    - #### NOT_FOUND

          public static final int NOT_FOUND

      See Also:
        Constant Field Values

    - #### OK

          public static final int OK

      See Also:
        Constant Field Values

    - #### PARTIAL_CONTENT

          public static final int PARTIAL_CONTENT

      See Also:
        Constant Field Values

    - #### PRECONDITION_FAILED

          public static final int PRECONDITION_FAILED

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### HTTPStatus

          public HTTPStatus()

      Creates a new empty HTTPStatus with default values.

    - #### 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

    - #### 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

  - ### Method Detail

    - #### 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

    - #### getReasonPhrase

          public String getReasonPhrase()

      Gets the reason phrase.
      Returns:
        the reason phrase

    - #### getStatusCode

          public int getStatusCode()

      Gets the status code.
      Returns:
        the status code

    - #### getVersion

          public String getVersion()

      Gets the HTTP version.
      Returns:
        the HTTP version

    - #### 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

    - #### 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

    - #### 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

    - #### setReasonPhrase

          public void setReasonPhrase(String value)

      Sets the reason phrase.
      Parameters:
        `value` - the reason phrase

    - #### setStatusCode

          public void setStatusCode(int value)

      Sets the status code.
      Parameters:
        `value` - the status code

    - #### setVersion

          public void setVersion(String value)

      Sets the HTTP version.
      Parameters:
        `value` - the HTTP version (e.g., "HTTP/1.1")