Simplify DelayedListenerRegistration functionality
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / DataTreeModificationOutput.java
index 17d4c4a71d78c11f24910e423cfd309da4cc4f5e..dde7e60a9237c2d1a52112ebb62901d2f86514f2 100644 (file)
@@ -12,7 +12,9 @@ import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import javax.xml.stream.XMLStreamException;
+import org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
@@ -30,10 +32,11 @@ public final class DataTreeModificationOutput {
     private DataTreeModificationOutput() {
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public static void toFile(File file, DataTreeModification modification) {
-        try(FileOutputStream outStream = new FileOutputStream(file)) {
+        try (FileOutputStream outStream = new FileOutputStream(file)) {
             modification.applyToCursor(new DataTreeModificationOutputCursor(new DataOutputStream(outStream)));
-        } catch(Exception e) {
+        } catch (IOException | RuntimeException e) {
             LOG.error("Error writing DataTreeModification to file {}", file, e);
         }
     }
@@ -48,10 +51,10 @@ public final class DataTreeModificationOutput {
         @Override
         public void delete(PathArgument child) {
             try {
-                output.write("\nDELETE -> ".getBytes());
-                output.write(next(child).toString().getBytes());
+                output.write("\nDELETE -> ".getBytes(StandardCharsets.UTF_8));
+                output.write(current().node(child).toString().getBytes(StandardCharsets.UTF_8));
                 output.writeByte('\n');
-            } catch(IOException e) {
+            } catch (IOException e) {
                 Throwables.propagate(e);
             }
         }
@@ -69,13 +72,13 @@ public final class DataTreeModificationOutput {
         private void outputPathAndNode(String name, PathArgument child, NormalizedNode<?, ?> data) {
             try {
                 output.writeByte('\n');
-                output.write(name.getBytes());
-                output.write(" -> ".getBytes());
-                output.write(next(child).toString().getBytes());
-                output.write(": \n".getBytes());
+                output.write(name.getBytes(StandardCharsets.UTF_8));
+                output.write(" -> ".getBytes(StandardCharsets.UTF_8));
+                output.write(current().node(child).toString().getBytes(StandardCharsets.UTF_8));
+                output.write(": \n".getBytes(StandardCharsets.UTF_8));
                 NormalizedNodeXMLOutput.toStream(output, data);
                 output.writeByte('\n');
-            } catch(IOException | XMLStreamException e) {
+            } catch (IOException | XMLStreamException e) {
                 Throwables.propagate(e);
             }
         }