Package com.helger.httpclient.response
Class ResponseHandlerString
java.lang.Object
com.helger.httpclient.response.ResponseHandlerString
- All Implemented Interfaces:
org.apache.hc.core5.http.io.HttpClientResponseHandler<String>
public class ResponseHandlerString
extends Object
implements org.apache.hc.core5.http.io.HttpClientResponseHandler<String>
Convert a valid HTTP response to a simple String object using the provided charset. The fallback
content type used internally is text/plain with charset iso-8859-1.
- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionResponseHandlerString(com.helger.mime.IMimeType aMimeType, Charset aCharset) ResponseHandlerString(org.apache.hc.core5.http.ContentType aDefault) -
Method Summary
Modifier and TypeMethodDescriptionfinal Charsetfinal org.apache.hc.core5.http.ContentTypefinal CharsethandleResponse(org.apache.hc.core5.http.ClassicHttpResponse aHttpResponse) final ResponseHandlerStringsetCharsetConsumer(Consumer<Charset> aCharsetConsumer) Set the charset consumer that is informed about the default character set in which the response is interpreted.final ResponseHandlerStringsetFallbackCharset(Charset aFallbackCharset) Set the fallback charset to be used, if the payload has no charset.
-
Constructor Details
-
ResponseHandlerString
public ResponseHandlerString(@Nonnull com.helger.mime.IMimeType aMimeType, @Nonnull Charset aCharset) -
ResponseHandlerString
public ResponseHandlerString(@Nonnull org.apache.hc.core5.http.ContentType aDefault)
-
-
Method Details
-
getDefaultContentType
@Nonnull public final org.apache.hc.core5.http.ContentType getDefaultContentType() -
getDefaultCharset
-
getFallbackCharset
- Returns:
- The fallback charset to be used, in case no charset can be determined from the content.
By default this is the HTTP default charset. Never
null. - Since:
- 9.7.2
- See Also:
-
setFallbackCharset
Set the fallback charset to be used, if the payload has no charset. By default the fallback charset is the charset of the Content Type.- Parameters:
aFallbackCharset- The fallback charset to be used. May not benull.- Returns:
- this for chaining
- Since:
- 9.7.2
-
getCharsetConsumer
-
setCharsetConsumer
@Nonnull public final ResponseHandlerString setCharsetConsumer(@Nullable Consumer<Charset> aCharsetConsumer) Set the charset consumer that is informed about the default character set in which the response is interpreted.- Parameters:
aCharsetConsumer- The charset consumer. May benull.- Returns:
- this for chaining
-
handleResponse
@Nullable public String handleResponse(@Nonnull org.apache.hc.core5.http.ClassicHttpResponse aHttpResponse) throws IOException - Specified by:
handleResponsein interfaceorg.apache.hc.core5.http.io.HttpClientResponseHandler<String>- Throws:
IOException
-