The documentation for InputStream has these 2 public methods...
int read(byte[] buffer) - Equivalent to read(buffer, 0, buffer.length)
int read(byte[] buffer, int offset, int length) - Reads at most length bytes from this stream and stores them in the byte array b starting at offset
The documentation for FileInputStream (a subclass of InputStream) has only one corresponding method to those above...
int read(byte[] buffer, int offset, int length)
So I'm thinking that if I use an instance of FileInputStream class, I can still call the
int read(byte[] buffer)
method, which will reference the corresponding
int read(byte[] buffer)
in the parent InputStream which then calls the over-ridden
int read(byte[] buffer, int offset, int length)
from FileInputStream (using values buffer, 0, buffer.length as parameters) to read from the stream.
Actually, FileInputStream overrides both the read(byte[]) and read(byte[], int, int) methods in InputStream. That fact is also apparent from the API documentation when you look at FileInputStream's method summary.
Beyond that, if and how they interact isn't really important, but just to satisfy your curiosity: the methods in FileInputStream don't call the super variants in InputStream, but instead invoke FileInputStream's private readBytes(byte[], int, int) method, which is declared native.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jack McGuire wrote:The documentation for FileInputStream (a subclass of InputStream) has only one corresponding method to those above...
Which documentation are you reading ? If you follow the auto-generated link for FileInputStream to the Java 7 javadoc, it shows both methods.
Jack McGuire
Greenhorn
Joined: Jan 24, 2012
Posts: 10
posted
0
I see what you're saying Jelle Klap in the Java 7 Documentation and I also see what your saying about the super variants in InputStream not being "called".
I should have said, Stuart, that I was looking at FileInputStream in Android documentation - (I'm experimenting with Android). In this documentation, it seems to say that int read(byte[] buffer) is inherited and not overridden.
Or so it would seem. A difference between Oracle Java and Android Java, maybe.