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

      @Nonnull public final Charset getDefaultCharset()
    • getFallbackCharset

      @Nonnull public final Charset 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

      @Nonnull public final ResponseHandlerString setFallbackCharset(@Nonnull Charset aFallbackCharset)
      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 be null.
      Returns:
      this for chaining
      Since:
      9.7.2
    • getCharsetConsumer

      @Nullable public final Consumer<Charset> 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 be null.
      Returns:
      this for chaining
    • handleResponse

      @Nullable public String handleResponse(@Nonnull org.apache.hc.core5.http.ClassicHttpResponse aHttpResponse) throws IOException
      Specified by:
      handleResponse in interface org.apache.hc.core5.http.io.HttpClientResponseHandler<String>
      Throws:
      IOException