java.lang.Object
org.codelibs.curl.CurlResponse
- All Implemented Interfaces:
Closeable,AutoCloseable
The CurlResponse class represents the response from a cURL request.
It implements the Closeable interface to allow proper resource management.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the content cache if it is not null.<T> TgetContent(Function<CurlResponse, T> parser) Gets the content of the response using the provided parser function.Gets the content of the response as an InputStream.Gets the content of the response as a string.Gets the exception that occurred while accessing the content, if any.Gets the encoding used for the response content.Gets the headers of the response.getHeaderValue(String name) Gets the value of the specified header.String[]getHeaderValues(String name) Gets the values of the specified header.intGets the HTTP status code of the response.voidsetContentCache(ContentCache contentCache) Sets the content cache for the response.voidSets the exception that occurred while accessing the content.voidsetEncoding(String encoding) Sets the encoding for the response content.voidsetHeaders(Map<String, List<String>> headers) Sets the headers for the response.voidsetHttpStatusCode(int httpStatusCode) Sets the HTTP status code for the response.
-
Constructor Details
-
CurlResponse
public CurlResponse()
-
-
Method Details
-
close
Closes the content cache if it is not null.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs.
-
getContent
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
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
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
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
Gets the encoding used for the response content.- Returns:
- the encoding.
-
setEncoding
Sets the encoding for the response content.- Parameters:
encoding- the encoding to set.
-
setContentException
Sets the exception that occurred while accessing the content.- Parameters:
e- the exception to set.
-
getContentException
Gets the exception that occurred while accessing the content, if any.- Returns:
- the exception, or null if no exception occurred.
-
setHeaders
Sets the headers for the response.- Parameters:
headers- the headers to set.
-
getHeaders
Gets the headers of the response.- Returns:
- the headers.
-
getHeaderValues
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
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.
-