mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-31 11:30:39 +00:00
Clean up base package
This commit is contained in:
parent
382d8d22d0
commit
fc8b6d0fcb
60 changed files with 102 additions and 100 deletions
35
src/main/java/org/asamk/signal/output/JsonWriterImpl.java
Normal file
35
src/main/java/org/asamk/signal/output/JsonWriterImpl.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package org.asamk.signal.output;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.asamk.signal.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
public class JsonWriterImpl implements JsonWriter {
|
||||
|
||||
private final Writer writer;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public JsonWriterImpl(final Writer writer) {
|
||||
this.writer = writer;
|
||||
this.objectMapper = Util.createJsonObjectMapper();
|
||||
}
|
||||
|
||||
public synchronized void write(final Object object) {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue