Cleanup java warnings and correct file handle leak