Details
Description
It is always a good practice to close the IO streams in a finally block..
For example, look at the following piece of code in the Writer class of BloomMapFile
BloomMapFile .java
public synchronized void close() throws IOException { super.close(); DataOutputStream out = fs.create(new Path(dir, BLOOM_FILE_NAME), true); bloomFilter.write(out); out.flush(); out.close(); }
If an exception occurs during fs.create or on any other line, out.close() will not be executed..
The following can reduce the scope of resorce leaks..
BloomMapFile .java
public synchronized void close() throws IOException { super.close(); DataOutputStream out = null; try{ out = fs.create(new Path(dir, BLOOM_FILE_NAME), true); bloomFilter.write(out); out.flush(); }finally{ IOUtils.closeStream(out); }