Questions tagged «bufferedinputstream»

4
为什么BufferedInputStream将字段复制到局部变量而不是直接使用该字段
当我从中读取源代码时java.io.BufferedInputStream.getInIfOpen(),我很困惑为什么它编写了这样的代码: /** * Check to make sure that underlying input stream has not been * nulled out due to close; if not return it; */ private InputStream getInIfOpen() throws IOException { InputStream input = in; if (input == null) throw new IOException("Stream closed"); return input; } 为什么使用别名而不是in直接使用field变量,如下所示: /** * Check …

6
从OKHTTP下载二进制文件
我在我的Android应用程序中使用OKHTTP客户端进行联网。 此示例显示了如何上传二进制文件。我想知道如何使用OKHTTP客户端获取二进制文件下载的输入流。 这是示例的清单: public class InputStreamRequestBody extends RequestBody { private InputStream inputStream; private MediaType mediaType; public static RequestBody create(final MediaType mediaType, final InputStream inputStream) { return new InputStreamRequestBody(inputStream, mediaType); } private InputStreamRequestBody(InputStream inputStream, MediaType mediaType) { this.inputStream = inputStream; this.mediaType = mediaType; } @Override public MediaType contentType() { return mediaType; …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.