Added additional exception handling where the code touches Java NIO.