Class HttpResponseBody


  • public class HttpResponseBody
    extends HttpBody
    • Constructor Detail

      • HttpResponseBody

        public HttpResponseBody()
        Constructs a HttpResponseBody with no contents (that is, zero length).
      • HttpResponseBody

        public HttpResponseBody​(int capacity)
        Constructs a HttpResponseBody with the given initial capacity.

        The initial capacity is limited to prevent allocating big arrays.

        Parameters:
        capacity - the initial capacity
        See Also:
        HttpBody.LIMIT_INITIAL_CAPACITY
      • HttpResponseBody

        public HttpResponseBody​(java.lang.String contents)
        Constructs a HttpResponseBody with the given contents, using default charset for String related operations.

        If the given contents are null the HttpResponseBody will have no content.

        Note: If the contents are not representable with the default charset it might lead to data loss.

        Parameters:
        contents - the contents of the body, might be null
        See Also:
        HttpResponseBody(byte[]), HttpBody.DEFAULT_CHARSET
      • HttpResponseBody

        public HttpResponseBody​(byte[] contents)
        Constructs a HttpResponseBody with the given contents.

        If the given contents are null the HttpResponseBody will have no content.

        Parameters:
        contents - the contents of the body, might be null
        Since:
        2.5.0
    • Method Detail

      • determineCharset

        protected java.nio.charset.Charset determineCharset​(java.lang.String contents)
        Description copied from class: HttpBody
        Determines the Charset of the given contents, that are being set to the body.

        An attempt to prevent data loss when new contents are set without a Charset.

        By default returns null.

        Overrides:
        determineCharset in class HttpBody
        Parameters:
        contents - the contents being set to the body
        Returns:
        the Charset, or null if not known.
      • createString

        protected java.lang.String createString​(java.nio.charset.Charset currentCharset)
        Description copied from class: HttpBody
        Returns the String representation of the body.

        Called when the cached string representation is no longer up-to-date.

        Overrides:
        createString in class HttpBody
        Parameters:
        currentCharset - the current Charset set, null if none
        Returns:
        the String representation of the body
        See Also:
        HttpBody.getBytes()