fixed receiving blank lines on stdin

This commit is contained in:
technillogue 2020-11-15 17:02:24 +00:00
parent 5f9d4f89e6
commit a746b8aae7
2 changed files with 30 additions and 31 deletions

View file

@ -30,43 +30,42 @@ import org.whispersystems.signalservice.api.util.InvalidNumberException;
class InputReader implements Runnable { class InputReader implements Runnable {
private volatile boolean alive = true; private volatile boolean alive = true;
private Manager m; private Manager m;
public void terminate() { public void terminate() {
this.alive = false; this.alive = false;
}
InputReader (final Manager m) {
this.m = m;
} }
InputReader (final Manager m) {
this.m = m;
}
@Override @Override
public void run() { public void run() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (alive) { while (alive) {
try { try {
String in = br.readLine(); String in = br.readLine();
String args[] = in.split(":", 2); // properly this ought to be json or some sort of serialization to not miss multiline messages
// properly this ought to be json or some sort of serialization to not miss multiline messages if (in != null && in.split(":", 2).length == 2) {
if (args.length == 2) { String args[] = in.split(":", 2);
String message = args[1]; String message = args[1];
List<String> recipients = new ArrayList<String>(); List<String> recipients = new ArrayList<String>();
recipients.add(args[0]); recipients.add(args[0]);
List<String> attachments = new ArrayList<>(); List<String> attachments = new ArrayList<>();
try { try {
System.out.println("sent '" + message + "' to " + args[0]); System.out.println("sent '" + message + "' to " + args[0]);
this.m.sendMessage(message, attachments, recipients); this.m.sendMessage(message, attachments, recipients);
} catch (AssertionError | EncapsulatedExceptions| AttachmentInvalidException | InvalidNumberException e) { } catch (AssertionError | EncapsulatedExceptions| AttachmentInvalidException | InvalidNumberException e) {
System.err.println("aaaaaa (DaemonCommand L59)"); System.err.println("aaaaaa (DaemonCommand L59)");
e.printStackTrace(System.out); e.printStackTrace(System.err);
} }
} }
} catch (IOException e) {
} catch (IOException e) { System.err.println("aaaaaa (DaemonCommand L64)");
System.err.println(e); System.err.println(e);
} }
// getMessageSender().sendTyping(signalServiceAddress?, ....) // getMessageSender().sendTyping(signalServiceAddress?, ....)
}
}
} }
} }
@ -120,7 +119,7 @@ public class DaemonCommand implements LocalCommand {
ns.getBoolean("json") ns.getBoolean("json")
? new JsonReceiveMessageHandler(m) ? new JsonReceiveMessageHandler(m)
: new ReceiveMessageHandler(m) : new ReceiveMessageHandler(m)
/*true*/); /*true*/);
return 0; return 0;
} catch (IOException e) { } catch (IOException e) {
System.err.println("Error while receiving messages: " + e.getMessage()); System.err.println("Error while receiving messages: " + e.getMessage());