Enumeration<URL> packageFiles = null;
try {
packageFiles = aClassLoader.getResources(CHECKSTYLE_PACKAGES);
}
catch (IOException e) {
throw new CheckstyleException(
"unable to get package file resources", e);
}
//create the loader outside the loop to prevent PackageObjectFactory
//being created anew for each file
final PackageNamesLoader namesLoader = newPackageNamesLoader();
while ((null != packageFiles) && packageFiles.hasMoreElements()) {
final URL aPackageFile = packageFiles.nextElement();
InputStream stream = null;
try {
stream = new BufferedInputStream(aPackageFile.openStream());
final InputSource source = new InputSource(stream);
loadPackageNamesSource(source, "default package names",
namesLoader);
}
catch (IOException e) {
throw new CheckstyleException(
"unable to open " + aPackageFile, e);
}
finally {
if (stream != null) {
try {
stream.close();
}
catch (IOException e) {
throw new CheckstyleException(
"error closing stream", e);
}
}
}
}