java.lang.Object
org.miaixz.bus.http.plugin.httpv.CoverResult.Real
- All Implemented Interfaces:
CoverResult
- Enclosing interface:
CoverResult
The concrete implementation of
CoverResult.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.miaixz.bus.http.plugin.httpv.CoverResult
CoverResult.Body, CoverResult.Real, CoverResult.State -
Constructor Summary
ConstructorsConstructorDescriptionReal(CoverHttp<?> coverHttp, CoverResult.State state) Constructs a result with a final state (e.g., CANCELED).Real(CoverHttp<?> coverHttp, CoverResult.State state, IOException error) Constructs a result from a failure.Real(CoverHttp<?> coverHttp, CoverTasks.Executor executor) Constructs a result with an executor, to be populated later.Real(CoverHttp<?> coverHttp, Response response, CoverTasks.Executor executor) Constructs a result from a successful response. -
Method Summary
Modifier and TypeMethodDescriptionclose()Closes the underlying response.voidexception(CoverResult.State state, IOException error) Sets the result to a failure state.getBody()Retrieves the response body handler.longGets the response body length as specified by the 'Content-Length' header.getError()Retrieves the exception that occurred during execution, if any.Retrieves the first header value for a given name.Retrieves the headers from the HTTP response.getHeaders(String name) Retrieves all header values for a given name.Gets the raw HttpdResponse.getState()Retrieves the final state of the HTTP execution.intRetrieves the HTTP status code from the response.booleanChecks if the response was successful (i.e., the status code is in the range [200..299]).voidSets the result to a success state with a response.toString()
-
Constructor Details
-
Real
Constructs a result with a final state (e.g., CANCELED).- Parameters:
coverHttp- The original HTTP task.state- The final state.
-
Real
Constructs a result from a successful response.- Parameters:
coverHttp- The original HTTP task.response- The raw HTTP response.executor- The task executor.
-
Real
Constructs a result with an executor, to be populated later.- Parameters:
coverHttp- The original HTTP task.executor- The task executor.
-
Real
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
Sets the result to a failure state.- Parameters:
state- The failure state.error- The exception.
-
response
Sets the result to a success state with a response.- Parameters:
response- The raw HTTP response.
-
getState
Description copied from interface:CoverResultRetrieves the final state of the HTTP execution.- Specified by:
getStatein interfaceCoverResult- Returns:
- The execution
CoverResult.State.
-
getStatus
public int getStatus()Description copied from interface:CoverResultRetrieves the HTTP status code from the response.- Specified by:
getStatusin interfaceCoverResult- Returns:
- The HTTP status code (e.g., 200, 404). Returns 0 if no response was received.
-
isSuccessful
public boolean isSuccessful()Description copied from interface:CoverResultChecks if the response was successful (i.e., the status code is in the range [200..299]).- Specified by:
isSuccessfulin interfaceCoverResult- Returns:
trueif the response was successful,falseotherwise.
-
getHeaders
Description copied from interface:CoverResultRetrieves the headers from the HTTP response.- Specified by:
getHeadersin interfaceCoverResult- Returns:
- The response
Headers.
-
getHeaders
Description copied from interface:CoverResultRetrieves all header values for a given name.- Specified by:
getHeadersin interfaceCoverResult- Parameters:
name- The case-insensitive header name.- Returns:
- A list of header values, or an empty list if the header is not present.
-
getHeader
Description copied from interface:CoverResultRetrieves the first header value for a given name.- Specified by:
getHeaderin interfaceCoverResult- Parameters:
name- The case-insensitive header name.- Returns:
- The header value, or
nullif the header is not present.
-
getContentLength
public long getContentLength()Description copied from interface:CoverResultGets the response body length as specified by the 'Content-Length' header. Note: For HEAD requests, this method may return a non-zero value, butCoverResult.Body.getLength()will return 0 because there is no actual body content.- Specified by:
getContentLengthin interfaceCoverResult- Returns:
- The content length in bytes, or 0 if not specified.
-
getBody
Description copied from interface:CoverResultRetrieves the response body handler.- Specified by:
getBodyin interfaceCoverResult- Returns:
- The
CoverResult.Bodyobject for consuming the response content.
-
getError
Description copied from interface:CoverResultRetrieves the exception that occurred during execution, if any.- Specified by:
getErrorin interfaceCoverResult- Returns:
- The
IOExceptionthat caused the failure, ornullif the request was successful.
-
getResponse
Gets the raw HttpdResponse.- Returns:
- The raw response object.
-
toString
-
close
Description copied from interface:CoverResultCloses the underlying response. This should be called to release resources, especially if the response body is not fully consumed.- Specified by:
closein interfaceCoverResult- Returns:
- This
CoverResultinstance.
-