Rui
Rui

Reputation: 3667

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

As a new xz-javadoc user, I am trying to use the XZInputStream to read decompressed bytes. Thus I am reading the xz-javadoc (http://tukaani.org/xz/xz-javadoc/org/tukaani/xz/XZInputStream.html).

In the doc page, there is the following text in the description of read() method:

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.

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

Upvotes: 0

Views: 18

Answers (1)

Tilman Hausherr
Tilman Hausherr

Reputation: 18926

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

it means this:

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

So although you're reading byte by byte, your input is buffered. There's also a longer explanation here.

Upvotes: 1

Related Questions