Class CurlResponse

java.lang.Object
org.codelibs.curl.CurlResponse
All Implemented Interfaces:
Closeable, AutoCloseable

public class CurlResponse extends Object implements Closeable
The CurlResponse class represents the response from a cURL request. It implements the Closeable interface to allow proper resource management.
  • Constructor Details

    • CurlResponse

      public CurlResponse()
  • Method Details

    • close

      public void close() throws IOException
      Closes the content cache if it is not null.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs.
    • getContent

      public <T> T getContent(Function<CurlResponse,T> parser)
      Gets the content of the response using the provided parser function.
      Type Parameters:
      T - the type of the parsed content.
      Parameters:
      parser - the function to parse the content.
      Returns:
      the parsed content.
    • getContentAsString

      public String getContentAsString()
      Gets the content of the response as a string.
      Returns:
      the content as a string.
      Throws:
      CurlException - if an error occurs while accessing the content.
    • getContentAsStream

      public InputStream getContentAsStream() throws IOException
      Gets the content of the response as an InputStream.
      Returns:
      the content as an InputStream.
      Throws:
      IOException - if an I/O error occurs.
      CurlException - if the content does not exist.
    • setContentCache

      public void setContentCache(ContentCache contentCache)
      Sets the content cache for the response.
      Parameters:
      contentCache - the content cache to set.
    • getHttpStatusCode

      public int getHttpStatusCode()
      Gets the HTTP status code of the response.
      Returns:
      the HTTP status code.
    • setHttpStatusCode

      public void setHttpStatusCode(int httpStatusCode)
      Sets the HTTP status code for the response.
      Parameters:
      httpStatusCode - the HTTP status code to set.
    • getEncoding

      public String getEncoding()
      Gets the encoding used for the response content.
      Returns:
      the encoding.
    • setEncoding

      public void setEncoding(String encoding)
      Sets the encoding for the response content.
      Parameters:
      encoding - the encoding to set.
    • setContentException

      public void setContentException(Exception e)
      Sets the exception that occurred while accessing the content.
      Parameters:
      e - the exception to set.
    • getContentException

      public Exception getContentException()
      Gets the exception that occurred while accessing the content, if any.
      Returns:
      the exception, or null if no exception occurred.
    • setHeaders

      public void setHeaders(Map<String,List<String>> headers)
      Sets the headers for the response.
      Parameters:
      headers - the headers to set.
    • getHeaders

      public Map<String,List<String>> getHeaders()
      Gets the headers of the response.
      Returns:
      the headers.
    • getHeaderValues

      public String[] getHeaderValues(String name)
      Gets the values of the specified header.
      Parameters:
      name - the name of the header.
      Returns:
      an array of header values, or an empty array if the header does not exist.
    • getHeaderValue

      public String getHeaderValue(String name)
      Gets the value of the specified header.
      Parameters:
      name - the name of the header.
      Returns:
      the header value, or null if the header does not exist.