Class HttpFileResponse

All Implemented Interfaces:
AutoCloseable

public class HttpFileResponse extends HttpClientResponse<InputStream> implements 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 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

      public String getHeader(String name)
      Get the value of a specific response header.
      Overrides:
      getHeader in class HttpClientResponse<InputStream>
      Parameters:
      name - the header name (case-insensitive)
      Returns:
      the header value, or null if the header is not present
    • getContentType

      public ContentType 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

      public void close() throws HttpClientException
      Close the underlying HTTP response and release any system resources. This method is idempotent and can be called multiple times safely.
      Specified by:
      close in interface AutoCloseable
      Throws:
      HttpClientException - if an error occurs while closing