Package com.squareup.okhttp
Class ResponseBody
- java.lang.Object
-
- com.squareup.okhttp.ResponseBody
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
RealResponseBody
public abstract class ResponseBody extends Object implements Closeable
-
-
Constructor Summary
Constructors Constructor Description ResponseBody()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description byte[]bytes()InputStreambyteStream()ReadercharStream()Returns the response as a character stream decoded with the charset of the Content-Type header.voidclose()Closes the object and release any system resources it holds.abstract longcontentLength()Returns the number of bytes in that will returned bybytes(), orbyteStream(), or -1 if unknown.abstract MediaTypecontentType()static ResponseBodycreate(MediaType contentType, byte[] content)Returns a new response body that transmitscontent.static ResponseBodycreate(MediaType contentType, long contentLength, BufferedSource content)Returns a new response body that transmitscontent.static ResponseBodycreate(MediaType contentType, String content)Returns a new response body that transmitscontent.abstract BufferedSourcesource()Stringstring()Returns the response as a string decoded with the charset of the Content-Type header.
-
-
-
Method Detail
-
contentType
public abstract MediaType contentType()
-
contentLength
public abstract long contentLength() throws IOExceptionReturns the number of bytes in that will returned bybytes(), orbyteStream(), or -1 if unknown.- Throws:
IOException
-
byteStream
public final InputStream byteStream() throws IOException
- Throws:
IOException
-
source
public abstract BufferedSource source() throws IOException
- Throws:
IOException
-
bytes
public final byte[] bytes() throws IOException- Throws:
IOException
-
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 IOExceptionDescription copied from interface:CloseableCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
create
public static ResponseBody create(MediaType contentType, String content)
Returns a new response body that transmitscontent. IfcontentTypeis 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 transmitscontent.
-
create
public static ResponseBody create(MediaType contentType, long contentLength, BufferedSource content)
Returns a new response body that transmitscontent.
-
-