Class ResponseBody

    • Constructor Detail

      • ResponseBody

        public ResponseBody()
    • Method Detail

      • contentType

        public abstract MediaType contentType()
      • charStream

        public final Reader charStream()
                                throws IOException
        Returns the response as a character stream decoded with the charset of the Content-Type header. If that header is either absent or lacks a charset, this will attempt to decode the response body as UTF-8.
        Throws:
        IOException
      • string

        public final String string()
                            throws IOException
        Returns the response as a string decoded with the charset of the Content-Type header. If that header is either absent or lacks a charset, this will attempt to decode the response body as UTF-8.
        Throws:
        IOException
      • close

        public void close()
                   throws IOException
        Description copied from interface: Closeable
        Closes the object and release any system resources it holds.

        Although only the first call has any effect, it is safe to call close multiple times on the same object. This is more lenient than the overridden AutoCloseable.close(), which may be called at most once.

        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        IOException
      • create

        public static ResponseBody create​(MediaType contentType,
                                          String content)
        Returns a new response body that transmits content. If contentType is non-null and lacks a charset, this will use UTF-8.
      • create

        public static ResponseBody create​(MediaType contentType,
                                          byte[] content)
        Returns a new response body that transmits content.