Module bus.http

Class CoverResult.Real

java.lang.Object
org.miaixz.bus.http.plugin.httpv.CoverResult.Real
All Implemented Interfaces:
CoverResult
Enclosing interface:
CoverResult

public static class CoverResult.Real extends Object implements CoverResult
The concrete implementation of CoverResult.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • Real

      public Real(CoverHttp<?> coverHttp, CoverResult.State state)
      Constructs a result with a final state (e.g., CANCELED).
      Parameters:
      coverHttp - The original HTTP task.
      state - The final state.
    • Real

      public Real(CoverHttp<?> coverHttp, Response response, CoverTasks.Executor executor)
      Constructs a result from a successful response.
      Parameters:
      coverHttp - The original HTTP task.
      response - The raw HTTP response.
      executor - The task executor.
    • Real

      public Real(CoverHttp<?> coverHttp, CoverTasks.Executor executor)
      Constructs a result with an executor, to be populated later.
      Parameters:
      coverHttp - The original HTTP task.
      executor - The task executor.
    • Real

      public Real(CoverHttp<?> coverHttp, CoverResult.State state, IOException error)
      Constructs a result from a failure.
      Parameters:
      coverHttp - The original HTTP task.
      state - The failure state.
      error - The exception that caused the failure.
  • Method Details

    • exception

      public void exception(CoverResult.State state, IOException error)
      Sets the result to a failure state.
      Parameters:
      state - The failure state.
      error - The exception.
    • response

      public void response(Response response)
      Sets the result to a success state with a response.
      Parameters:
      response - The raw HTTP response.
    • getState

      public CoverResult.State getState()
      Description copied from interface: CoverResult
      Retrieves the final state of the HTTP execution.
      Specified by:
      getState in interface CoverResult
      Returns:
      The execution CoverResult.State.
    • getStatus

      public int getStatus()
      Description copied from interface: CoverResult
      Retrieves the HTTP status code from the response.
      Specified by:
      getStatus in interface CoverResult
      Returns:
      The HTTP status code (e.g., 200, 404). Returns 0 if no response was received.
    • isSuccessful

      public boolean isSuccessful()
      Description copied from interface: CoverResult
      Checks if the response was successful (i.e., the status code is in the range [200..299]).
      Specified by:
      isSuccessful in interface CoverResult
      Returns:
      true if the response was successful, false otherwise.
    • getHeaders

      public Headers getHeaders()
      Description copied from interface: CoverResult
      Retrieves the headers from the HTTP response.
      Specified by:
      getHeaders in interface CoverResult
      Returns:
      The response Headers.
    • getHeaders

      public List<String> getHeaders(String name)
      Description copied from interface: CoverResult
      Retrieves all header values for a given name.
      Specified by:
      getHeaders in interface CoverResult
      Parameters:
      name - The case-insensitive header name.
      Returns:
      A list of header values, or an empty list if the header is not present.
    • getHeader

      public String getHeader(String name)
      Description copied from interface: CoverResult
      Retrieves the first header value for a given name.
      Specified by:
      getHeader in interface CoverResult
      Parameters:
      name - The case-insensitive header name.
      Returns:
      The header value, or null if the header is not present.
    • getContentLength

      public long getContentLength()
      Description copied from interface: CoverResult
      Gets the response body length as specified by the 'Content-Length' header. Note: For HEAD requests, this method may return a non-zero value, but CoverResult.Body.getLength() will return 0 because there is no actual body content.
      Specified by:
      getContentLength in interface CoverResult
      Returns:
      The content length in bytes, or 0 if not specified.
    • getBody

      public CoverResult.Body getBody()
      Description copied from interface: CoverResult
      Retrieves the response body handler.
      Specified by:
      getBody in interface CoverResult
      Returns:
      The CoverResult.Body object for consuming the response content.
    • getError

      public IOException getError()
      Description copied from interface: CoverResult
      Retrieves the exception that occurred during execution, if any.
      Specified by:
      getError in interface CoverResult
      Returns:
      The IOException that caused the failure, or null if the request was successful.
    • getResponse

      public Response getResponse()
      Gets the raw Httpd Response.
      Returns:
      The raw response object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public CoverResult close()
      Description copied from interface: CoverResult
      Closes the underlying response. This should be called to release resources, especially if the response body is not fully consumed.
      Specified by:
      close in interface CoverResult
      Returns:
      This CoverResult instance.