refactored closing input streams

Former-commit-id: 04c8b13428a4c7a215058bf54d47c62374d6a946
This commit is contained in:
Jeremy Long
2014-03-01 06:56:42 -05:00
parent ab766ce85b
commit b3d08e4cb8

View File

@@ -393,11 +393,7 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer {
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
} finally { } finally {
try { closeStream(input);
input.close();
} catch (IOException ex) {
Logger.getLogger(JarAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
}
} }
Model model = null; Model model = null;
FileInputStream fis = null; FileInputStream fis = null;
@@ -423,17 +419,26 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer {
Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, null, ex); Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINE, null, ex);
throw ex; throw ex;
} finally { } finally {
if (fis != null) { closeStream(fis);
try {
fis.close();
} catch (IOException ex) {
Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINEST, null, ex);
}
}
} }
return model; return model;
} }
/**
* Silently closes an input stream ignoring errors.
*
* @param stream an input stream to close
*/
private void closeStream(InputStream stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException ex) {
Logger.getLogger(JarAnalyzer.class.getName()).log(Level.FINEST, null, ex);
}
}
}
/** /**
* Retrieves the specified POM from a jar file and converts it to a Model. * Retrieves the specified POM from a jar file and converts it to a Model.
* *