my first question on stackoverflow, I'm exited ;)
When using stream chains it's usually good pratice to just close the last stream in the chain, since the close() operation should propagate through all streams of the chain.
What would be considered good practice when combining try-with-ressource statements and stream chaining?
a) Creating all streams inside the try statement:
try (InputStream processIn = p.getInputStream();
InputStreamReader inReader = new InputStreamReader(processIn);
BufferedReader input = new BufferedReader(inReader)) {
.
.
}
Or b) just the last member of the chain:
InputStream processIn = p.getInputStream();
InputStreamReader inReader = new InputStreamReader(processIn);
try (BufferedReader input = new BufferedReader(inReader)) {
.
.
}
I guess both versions will work in the end, but I assume a) will generate duplicate close() calls, won't it?