No, you donβt have to.
Since the decorator approach used for streams in Java can create new streams or readers by attaching them to others, this will be automatically handled by the InputStreamReader implementation.
If you look at its source InputStreamReader.java , you will see that:
private final StreamDecoder sd; public InputStreamReader(InputStream in) { ... sd = StreamDecoder.forInputStreamReader(in, this, (String)null); ... } public void close() throws IOException { sd.close(); }
Thus, the close operation actually closes the InputStream underlying the stream reader.
EDIT: I want to be sure that closing StreamDecoder also works on the input stream, stay tuned.
Checked in StreamDecoder.java
void implClose() throws IOException { if (ch != null) ch.close(); else in.close(); }
which is called when sd close is called.
Jack 02 Sep 2018-10-09T00: 00Z
source share