Java Code Examples for okhttp3.internal.Util#bomAwareCharset()
The following examples show how to use
okhttp3.internal.Util#bomAwareCharset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseBody.java From styT with Apache License 2.0 | 5 votes |
@Override public int read(char[] cbuf, int off, int len) throws IOException { if (closed) throw new IOException("Stream closed"); Reader delegate = this.delegate; if (delegate == null) { Charset charset = Util.bomAwareCharset(source, this.charset); delegate = this.delegate = new InputStreamReader(source.inputStream(), charset); } return delegate.read(cbuf, off, len); }
Example 2
Source File: ResponseBody.java From AndroidProjects with MIT License | 5 votes |
@Override public int read(char[] cbuf, int off, int len) throws IOException { if (closed) throw new IOException("Stream closed"); Reader delegate = this.delegate; if (delegate == null) { Charset charset = Util.bomAwareCharset(source, this.charset); delegate = this.delegate = new InputStreamReader(source.inputStream(), charset); } return delegate.read(cbuf, off, len); }
Example 3
Source File: ResponseBody.java From styT with Apache License 2.0 | 3 votes |
/** * 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); } }
Example 4
Source File: ResponseBody.java From AndroidProjects with MIT License | 3 votes |
/** * 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); } }