]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/JsonWriter.java
Add dbus SignalControl interface to register/verify/link accounts
[signal-cli] / src / main / java / org / asamk / signal / JsonWriter.java
index 8aed44875cdc2d0f76498da7012849989aa3ae86..c48fd095bdb9c1bef0758ba29f66edf0b0cf588e 100644 (file)
@@ -13,27 +13,31 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.nio.charset.StandardCharsets;
 
-public class JsonWriter {
+public class JsonWriter implements OutputWriter {
 
     private final Writer writer;
     private final ObjectMapper objectMapper;
 
-    public JsonWriter(final OutputStream writer) {
-        this.writer = new BufferedWriter(new OutputStreamWriter(writer, StandardCharsets.UTF_8));
+    public JsonWriter(final OutputStream outputStream) {
+        this.writer = new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
 
         objectMapper = new ObjectMapper();
         objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY);
         objectMapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
     }
 
-    public void write(final Object object) throws IOException {
+    public void write(final Object object) {
         try {
-            objectMapper.writeValue(writer, object);
-        } catch (JsonProcessingException e) {
-            // Some issue with json serialization, probably caused by a bug
+            try {
+                objectMapper.writeValue(writer, object);
+            } catch (JsonProcessingException e) {
+                // Some issue with json serialization, probably caused by a bug
+                throw new AssertionError(e);
+            }
+            writer.write(System.lineSeparator());
+            writer.flush();
+        } catch (IOException e) {
             throw new AssertionError(e);
         }
-        writer.write(System.lineSeparator());
-        writer.flush();
     }
 }