本文整理了Java中okhttp3.internal.Util.bomAwareCharset()
方法的一些代码示例,展示了Util.bomAwareCharset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.bomAwareCharset()
方法的具体详情如下:
包路径:okhttp3.internal.Util
类名称:Util
方法名:bomAwareCharset
暂无
代码示例来源:origin: square/okhttp
@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);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
@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);
}
代码示例来源:origin: square/okhttp
/**
* 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);
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* 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);
}
}
代码示例来源:origin: com.github.ljun20160606/okhttp
@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);
}
代码示例来源:origin: apache/servicemix-bundles
@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);
}
代码示例来源:origin: opacapp/opacclient
private String readBody(Response response, String encoding) throws IOException {
ResponseBody body = response.body();
BufferedSource source = body.source();
MediaType contentType = body.contentType();
try {
Charset charset = Util.bomAwareCharset(source,
contentType != null ? contentType.charset(Charset.forName(encoding)) :
Charset.forName(encoding));
return source.readString(charset);
} finally {
Util.closeQuietly(source);
}
}
代码示例来源:origin: MuShare/Httper-Android
MediaType mediaType = body.contentType();
charset = Util.bomAwareCharset(body.source(), mediaType != null ? mediaType
.charset(UTF_8) : UTF_8).displayName();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream
代码示例来源:origin: com.github.ljun20160606/okhttp
/**
* 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);
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* 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);
}
}
内容来源于网络,如有侵权,请联系作者删除!