mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Move Writer creation out of WriterImpls
This commit is contained in:
parent
b5eef3ccad
commit
5dd602614c
4 changed files with 23 additions and 22 deletions
|
@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -49,16 +50,20 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
|
|||
m.setIgnoreAttachments(ignoreAttachments);
|
||||
|
||||
final var jsonOutputWriter = (JsonWriter) outputWriter;
|
||||
final var reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
final Supplier<String> lineSupplier = () -> {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
};
|
||||
final Supplier<String> lineSupplier = getLineSupplier(new InputStreamReader(System.in));
|
||||
|
||||
final var handler = new SignalJsonRpcDispatcherHandler(m, jsonOutputWriter, lineSupplier);
|
||||
handler.handleConnection();
|
||||
|
||||
private Supplier<String> getLineSupplier(final Reader reader) {
|
||||
final var bufferedReader = new BufferedReader(reader);
|
||||
return () -> {
|
||||
try {
|
||||
return bufferedReader.readLine();
|
||||
} catch (IOException e) {
|
||||
logger.error("Error occurred while reading line", e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue