/** * Returns the response as a character stream. * * <p>If the response starts with a <a href="https://en.wikipedia.org/wiki/Byte_order_mark">Byte * Order Mark (BOM)</a>, it is consumed and used to determine the charset of the response bytes. * * <p>Otherwise if the response has a Content-Type header that specifies a charset, that is used * to determine the charset of the response bytes. * * <p>Otherwise the response bytes are decoded as UTF-8. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new BomAwareReader(source(), charset())); }
/** * Returns the response as a string. * * <p>If the response starts with a <a href="https://en.wikipedia.org/wiki/Byte_order_mark">Byte * Order Mark (BOM)</a>, it is consumed and used to determine the charset of the response bytes. * * <p>Otherwise if the response has a Content-Type header that specifies a charset, that is used * to determine the charset of the response bytes. * * <p>Otherwise the response bytes are decoded as UTF-8. * * <p>This method loads entire response body into memory. If the response body is very large this * may trigger an {@link OutOfMemoryError}. Prefer to stream the response body if this is a * possibility for your response. */ public final String string() throws IOException { try (BufferedSource source = source()) { Charset charset = Util.bomAwareCharset(source, charset()); return source.readString(charset); } }
/** * Returns the response as a character stream. * * <p>If the response starts with a <a href="https://en.wikipedia.org/wiki/Byte_order_mark">Byte * Order Mark (BOM)</a>, it is consumed and used to determine the charset of the response bytes. * * <p>Otherwise if the response has a Content-Type header that specifies a charset, that is used * to determine the charset of the response bytes. * * <p>Otherwise the response bytes are decoded as UTF-8. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new BomAwareReader(source(), charset())); }
/** * Returns the response as a string. * * <p>If the response starts with a <a href="https://en.wikipedia.org/wiki/Byte_order_mark">Byte * Order Mark (BOM)</a>, it is consumed and used to determine the charset of the response bytes. * * <p>Otherwise if the response has a Content-Type header that specifies a charset, that is used * to determine the charset of the response bytes. * * <p>Otherwise the response bytes are decoded as UTF-8. * * <p>This method loads entire response body into memory. If the response body is very large this * may trigger an {@link OutOfMemoryError}. Prefer to stream the response body if this is a * possibility for your response. */ public final String string() throws IOException { try (BufferedSource source = source()) { Charset charset = Util.bomAwareCharset(source, charset()); return source.readString(charset); } }
/** * 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. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new InputStreamReader(byteStream(), charset())); }
/** * 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. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new InputStreamReader(byteStream(), charset())); }
/** * 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. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new InputStreamReader(byteStream(), charset())); }
/** * 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. */ public final String string() throws IOException { return new String(bytes(), charset().name()); }
/** * 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 in accordance to <a href="https://en.wikipedia.org/wiki/Byte_order_mark">its BOM</a> or * UTF-8. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new BomAwareReader(source(), charset())); }
/** * 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. */ public final String string() throws IOException { return new String(bytes(), charset().name()); }
/** * 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 in accordance to <a href="https://en.wikipedia.org/wiki/Byte_order_mark">its BOM</a> or * UTF-8. */ public final Reader charStream() { Reader r = reader; return r != null ? r : (reader = new BomAwareReader(source(), charset())); }
/** * 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. */ public final String string() throws IOException { return new String(bytes(), charset().name()); }
/** * 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 in * accordance to <a href="https://en.wikipedia.org/wiki/Byte_order_mark">its BOM</a> or UTF-8. * Closes {@link ResponseBody} automatically. * * <p>This method loads entire response body into memory. If the response body is very large this * may trigger an {@link OutOfMemoryError}. Prefer to stream the response body if this is a * possibility for your response. */ public final String string() throws IOException { BufferedSource source = source(); try { Charset charset = Util.bomAwareCharset(source, charset()); return source.readString(charset); } finally { Util.closeQuietly(source); } }
/** * 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 in * accordance to <a href="https://en.wikipedia.org/wiki/Byte_order_mark">its BOM</a> or UTF-8. * Closes {@link ResponseBody} automatically. * * <p>This method loads entire response body into memory. If the response body is very large this * may trigger an {@link OutOfMemoryError}. Prefer to stream the response body if this is a * possibility for your response. */ public final String string() throws IOException { BufferedSource source = source(); try { Charset charset = Util.bomAwareCharset(source, charset()); return source.readString(charset); } finally { Util.closeQuietly(source); } }