ByteArrayInputStream confusion

S

Sard

The ByteArrayInputStream class has a read method which is "the buffer
into which the data is read". How can this be possible if arguments
are always passed by value?


read

public int read(byte[] b,
int off,
int len)

Reads up to len bytes of data into an array of bytes from this
input stream. If pos equals count, then -1 is returned to indicate end
of file. Otherwise, the number k of bytes read is equal to the smaller
of len and count-pos. If k is positive, then bytes buf[pos] through
buf[pos+k-1] are copied into b[off] through b[off+k-1] in the manner
performed by System.arraycopy. The value k is added into pos and k is
returned.

This read method cannot block.

Overrides:
read in class InputStream

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
 
M

Michael Rauscher

Sard said:
The ByteArrayInputStream class has a read method which is "the buffer
into which the data is read". How can this be possible if arguments
are always passed by value?

The buffer you're referring to is an array of bytes (byte[]).

In Java arrays are objects. So the reference to that object (array) is
passed by value.

Bye
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top