This almost seems silly but what is the most reliable pattern to follow when closing an OutputStream? Right now I have something like the following which just seem to be try-catch-finally-overkill:
private void writeContentsToFile(OutputStream ostream, Properties contents) {
try {
contents.store(ostream, "comments");
}
catch (IOException e) {
throw new ResourceException("Failed to write contents", e);
}
finally {
try {
ostream.close();
}
catch (IOException e) { /* what can be done here anyway? */ }
}
}
Why close throws a checked exception is still a mystery to me. I can create wrapper method that does the close/catch block but if there is something already out there like FileUtil.closeFileAndThrowUncheckedException()
I would like to use it. This gets a bit more useful when you have lots of smaller projects with lots of devs; one way to do it right.