Skip to content

Instantly share code, notes, and snippets.

@yccheok
Created June 12, 2018 18:40
Show Gist options
  • Select an option

  • Save yccheok/8a8d98007eda1f218564fc21dac446af to your computer and use it in GitHub Desktop.

Select an option

Save yccheok/8a8d98007eda1f218564fc21dac446af to your computer and use it in GitHub Desktop.
/**
* Performs close operation on Closeable stream, without the need of
* writing cumbersome try...catch block.
*
* @param closeable The closeable stream.
*/
public static void close(Closeable closeable) {
// Instead of returning boolean, we will just simply swallow any
// exception silently. This is because this method will usually be
// invoked within finally block. If we are having control statement
// (return, break, continue) within finally block, a lot of surprise may
// happen.
// http://stackoverflow.com/questions/48088/returning-from-a-finally-block-in-java
if (null != closeable) {
try {
closeable.close();
} catch (IOException ex) {
Log.e(TAG, "", ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment