简体   繁体   English

BufferedInputStream.read(byte [] b,int off,int len)中的off参数

[英]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. offb中的索引,流将在其中开始输入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.

相关问题 Can BufferedInputStream.read(byte [] b,int off,int len)是否会返回0? 是否有重要的,破坏的InputStream可能会导致这种情况? - Can BufferedInputStream.read(byte[] b, int off, int len) ever return 0? Are there significant, broken InputStreams that might cause this? InputStream中的read(byte b[], int off, int len)方法和FileInputStream中的read(byte b[], int off, int len)方法一样吗? - Is the method read(byte b[], int off, int len) in InputStream same as the method read(byte b[], int off, int len) in FileInputStream? JAVA:InputStream.read(byte [] b,int off,int len)中的字节数组分配 - JAVA: Byte array allocation in InputStream.read(byte[] b, int off, int len) readFully(byte [] b,int off,int len)和EOFException - readFully(byte[] b, int off, int len) and EOFException InputStream read(byte [] b,int off,int len)-删除文件的其余部分? - InputStream read(byte[] b, int off, int len) - Drop the rest of the file? read(byte [] b,int off,int len):读取文件到最后 - read(byte[] b, int off, int len) : Reading A File To Its End DataOutputStream.write(byte b [],int off,int len)不会引发异常 - DataOutputStream.write(byte b[], int off, int len) don't throws exception 如何使用BufferedInputStream.read()获得真实的字节顺序? - How to get true byte order with BufferedInputStream.read()? 如何使用 read(char[] cbuf, int off, int len) 读取整个文件 - How to read whole file with read(char[] cbuf, int off, int len) 从类Reader读取(char [] cbuf,int off,int len) - Confusion on read(char[] cbuf, int off, int len) from class Reader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM