BUG-2839: remove dependencies on commons-io
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / mapping / ModuleInfoBundleTracker.java
index 48fdd8855de12c9735a9a10a25ae5b5a9382b7f0..56535e797b46bb7b6be4005f2fe8705c83d51fa3 100644 (file)
@@ -8,14 +8,13 @@
 package org.opendaylight.controller.config.manager.impl.osgi.mapping;
 
 import static java.lang.String.format;
-
-import java.io.InputStream;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import java.io.IOException;
 import java.net.URL;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
-
-import org.apache.commons.io.IOUtils;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
 import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
@@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
  */
 public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
 
-    private static final Logger logger = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
+    private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
 
     public static final String MODULE_INFO_PROVIDER_PATH_PREFIX = "META-INF/services/";
 
@@ -45,25 +44,24 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Co
     @Override
     public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(Bundle bundle, BundleEvent event) {
         URL resource = bundle.getEntry(MODULE_INFO_PROVIDER_PATH_PREFIX + YangModelBindingProvider.class.getName());
-        logger.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource);
+        LOG.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource);
         if(resource==null) {
             return null;
         }
         List<ObjectRegistration<YangModuleInfo>> registrations = new LinkedList<>();
 
-        try (InputStream inputStream = resource.openStream()) {
-            List<String> lines = IOUtils.readLines(inputStream);
-            for (String moduleInfoName : lines) {
-                logger.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle);
+        try {
+            for (String moduleInfoName : Resources.readLines(resource, Charsets.UTF_8)) {
+                LOG.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle);
                 YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle);
                 registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
             }
-
-        } catch (Exception e) {
-            logger.error("Error while reading {}", resource, e);
+        } catch (IOException e) {
+            LOG.error("Error while reading {}", resource, e);
             throw new RuntimeException(e);
         }
-        logger.trace("Got following registrations {}", registrations);
+
+        LOG.trace("Got following registrations {}", registrations);
         return registrations;
     }
 
@@ -111,7 +109,7 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Co
         } catch (NoClassDefFoundError e) {
 
 
-            logger.error("Error while executing getModuleInfo on {}", instance, e);
+            LOG.error("Error while executing getModuleInfo on {}", instance, e);
             throw e;
         }
     }
@@ -126,7 +124,7 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Co
     }
 
     public static String logMessage(String slfMessage, Object... params) {
-        logger.info(slfMessage, params);
+        LOG.info(slfMessage, params);
         String formatMessage = slfMessage.replaceAll("\\{\\}", "%s");
         return format(formatMessage, params);
     }