xz-javadoc > "Wrap it in BufferedInputStream if you need to read lots of data one byte at a time" 是什么意思

xz-javadoc > What is the meaning of "Wrap it in BufferedInputStream if you need to read lots of data one byte at a time"

作为 xz-javadoc 的新用户,我正在尝试使用 XZInputStream 来读取解压缩的字节。因此我正在阅读 xz-javadoc (http://tukaani.org/xz/xz-javadoc/org/tukaani/xz/XZInputStream.html).

在文档页面中,read()方法的描述中有如下文字:

Reading lots of data with read() from this input stream may be inefficient. Wrap it in BufferedInputStream if you need to read lots of data one byte at a time.

这是什么意思?将此输入流包装到 BufferedInputStream?

What is the meaning of this? wrap this input stream to BufferedInputStream?

意思是:

InputStream is = new BufferedInputStream(new XZInputStream(file));
int by;
while ((by = is.read()) != -1)
{
     // do stuff with "by"
}
is.close();

因此,尽管您正在逐字节读取,但您的输入已被缓冲。还有更长的解释here.