You can do IOUtils.closeWhileHandlingException to close these streams only if they are not null and silently