Package dev.galasa.http
Class HttpFileResponse
- All Implemented Interfaces:
AutoCloseable
Wrapper for HTTP file download responses. This class encapsulates the response
from file download operations, providing access to the response stream, headers,
and status information while hiding the underlying HTTP client implementation.
This class extends HttpClientResponse with InputStream content
and implements AutoCloseable to ensure proper resource cleanup. It should be used
in try-with-resources blocks:
try (HttpFileResponse response = client.getFileStream("/path/to/file")) {
InputStream stream = response.getContent();
// Process the stream
}
- Since:
- 0.47.0
-
Constructor Summary
ConstructorsConstructorDescriptionHttpFileResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse) Public constructor for creating HttpFileResponse from ClassicHttpResponse. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the underlying HTTP response and release any system resources.longGet the content length of the response, if known.Get the content type of the response.Get the value of a specific response header.booleanCheck if the response was successful (status code 2xx or 3xx).Methods inherited from class dev.galasa.http.HttpClientResponse
byteResponse, byteResponse, getContent, getheaders, getProtocolVersion, getStatusCode, getStatusLine, getStatusMessage, jaxbResponse, jaxbResponse, jaxbResponse, jaxbResponse, jsonResponse, jsonResponse, jsonResponse, jsonResponse, populateGenericValues, populateGenericValues, setContent, textResponse, textResponse, xmlResponse, xmlResponse, xmlResponse, xmlResponse
-
Constructor Details
-
HttpFileResponse
public HttpFileResponse(org.apache.hc.core5.http.ClassicHttpResponse httpResponse) throws HttpClientException Public constructor for creating HttpFileResponse from ClassicHttpResponse. Typically used internally by IHttpClient implementations.- Parameters:
httpResponse- the underlying HTTP response- Throws:
HttpClientException- if the response cannot be processed
-
-
Method Details
-
getHeader
Get the value of a specific response header.- Overrides:
getHeaderin classHttpClientResponse<InputStream>- Parameters:
name- the header name (case-insensitive)- Returns:
- the header value, or null if the header is not present
-
getContentType
Get the content type of the response.- Returns:
- the ContentType, or null if not specified
-
getContentLength
public long getContentLength()Get the content length of the response, if known.- Returns:
- the content length in bytes, or -1 if unknown
-
isSuccessful
public boolean isSuccessful()Check if the response was successful (status code 2xx or 3xx).- Returns:
- true if the status code is in the 200-399 range
-
close
Close the underlying HTTP response and release any system resources. This method is idempotent and can be called multiple times safely.- Specified by:
closein interfaceAutoCloseable- Throws:
HttpClientException- if an error occurs while closing
-