BUG 2839: Config: remove dependencies on commons-io
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / java / GeneratedObject.java
index 4ad080c..5eb58d5 100644 (file)
@@ -1,15 +1,15 @@
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import com.google.common.base.Optional;
 import com.google.common.collect.Maps;
-import org.apache.commons.io.FileUtils;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
-
+import com.google.common.io.Files;
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Map.Entry;
-
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
 
 public class GeneratedObject {
 
@@ -31,8 +31,10 @@ public class GeneratedObject {
 
     public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
         File dstFile = fqn.toFile(srcDirectory);
-        if (overwrite == true || dstFile.exists() == false) {
-            FileUtils.write(dstFile, content);
+        if (overwrite || !dstFile.exists()) {
+            Files.createParentDirs(dstFile);
+            Files.touch(dstFile);
+            Files.write(content, dstFile, StandardCharsets.UTF_8);
             return Optional.of(Maps.immutableEntry(fqn, dstFile));
         } else {
             return Optional.absent();
@@ -61,11 +63,8 @@ public class GeneratedObject {
 
         GeneratedObject that = (GeneratedObject) o;
 
-        if (!fqn.equals(that.fqn)) {
-            return false;
-        }
+        return fqn.equals(that.fqn);
 
-        return true;
     }
 
     @Override

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.