[英]The off parameter in BufferedInputStream.read(byte[] b, int off, int len)
The javadoc says the following. Javadoc说以下内容。
Parameters:
b - destination buffer.
off - offset at which to start storing bytes.
len - maximum number of bytes to read.
I would like to confirm my understanding of the "offset at which to start storing bytes". 我想确认我对“开始存储字节的偏移量”的理解。 Does this mean that
off
is "the index at the destination buffer b
at which to start storing bytes"? 这是否意味着“目标缓冲区
b
上开始存储字节的索引”为off
? It does sound like off
means it. 听起来确实像是
off
。 I think the method is more usable if off
is the "offset at the BufferedInputStream at which to start reading bytes", but I want to confirm. 我认为如果
off
是“开始读取字节的BufferedInputStream的偏移量”,则该方法更有用,但我想确认一下。 I tried looking at the source but it's hard to read. 我尝试查看源代码,但很难阅读。
A side question: When 1024 bytes of a stream is read, will the said 1024 bytes always be removed from the stream? 附带的问题:读取流的1024个字节时,是否总是将所述1024个字节从流中删除?
Yes. 是。
off
is the index in b
where the stream will start entering len
bytes. off
是b
中的索引,流将在其中开始输入len
个字节。
When 1024 bytes of a stream is read, will the said 1024 bytes always be removed from the stream?
当读取流的1024个字节时,是否总是将所述1024个字节从流中删除?
Using an InputStream
, you have no knowledge of what's going on underneath. 使用
InputStream
,您不知道其下发生了什么。 All you know are the methods available to you and what they do (what their documentation says). 您所知道的就是可以使用的方法及其用途(文档说明的内容)。 Implementations can do whatever they want.
实现可以做任何他们想做的事情。
Does this mean that off is "the index at the destination buffer b at which to start storing bytes"?
这是否意味着“目标缓冲区b上开始存储字节的索引”为off?
It's documented : "The first byte read is stored into element b[off]
". 记录在案 :“读取的第一个字节存储在元素
b[off]
”。
When 1024 bytes of a stream is read, will the said 1024 bytes always be removed from the stream?
当读取流的1024个字节时,是否总是将所述1024个字节从流中删除?
Of course, but you seem to be really asking whether 1024 bytes will always be read if you supply a buffer of 1024 bytes. 当然,但是您似乎真的在问如果提供1024个字节的缓冲区是否将始终读取1024个字节。 Answer is no.
答案是否定的。 It's documented : "there is an attempt to read at least one byte".
记录在案 :“试图读取至少一个字节”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.