properly release the file descriptors and avoid duplicate code
properly release the file descriptors and avoid duplicate code

apache/ant-ivy,jaikiran/ant-ivy,apache/ant-ivy,jaikiran/ant-ivy,apache/ant-ivy,twogee/ant-ivy,twogee/ant-ivy,jaikiran/ant-ivy,apache/ant-ivy,twogee/ant-ivy,jaikiran/ant-ivy,twogee/ant-ivy