I'm trying to write my input stream which extends InputStream and learnt the following
Input stream is an abstract class which contains abstract methods and implementation for some method it has. Noticed that InputStream contains an abstract method
public abstract int read() throws IOException;
I'm not very sure about what this method does. So, referred for someother inputstream which extends InputStream and got FilterInputStream
which extends InputStream
and the read method implementation in this is like
public int read() throws IOException {
return in.read();
}
in
here refers to the underlying input stream. Consider the constructor of FilterInputStream
which is like
protected FilterInputStream(InputStream in) {
this.in = in;
}
In read() method implementation this simply invokes the read method in its parent class which is InputStream
which is just an abstract method.
- What read() method in InputStream does?
- What happens when i invoke the read method of FSDataInputStream?
- Do we add read() method here just to avoid compilation error? Or do we have any other use with this?
I'm confused with these. Please help me know about it.