private final int port;
/** The nickname chooser. */
- private NicknameChooser nicknameChooser = new NicknameChooser() {
-
- @Override
- public String getNickname() {
- return RandomNickname.get();
- }
- };
+ private NicknameChooser nicknameChooser = RandomNickname::get;
/** The nickname. */
private String nickname = null;
while (connected) {
Reply reply = connectionHandler.readReply();
eventBus.post(new ReplyReceived(this, reply));
- logger.trace(String.format("<< %s", reply));
+ logger.trace(String.format("<< %s", addEscapeCharacters(reply.toString())));
String command = reply.command();
List<String> parameters = reply.parameters();
} finally {
established.set(false);
eventBus.unregister(this);
- logger.info("Closing Connection.");
+ logger.info(String.format("Closing Connection to %s:%d.", hostname, port));
try {
Closeables.close(connectionHandler, true);
} catch (IOException ioe1) {
// PRIVATE METHODS
//
+ private String addEscapeCharacters(String line) {
+ StringBuilder escaped = new StringBuilder();
+ for (char c : line.toCharArray()) {
+ if (c < 32) {
+ escaped.append("\\CTRL[").append((int) c).append("]");
+ } else {
+ escaped.append(c);
+ }
+ }
+ return escaped.toString();
+ }
+
/**
* Returns an item from the list, or {@link Optional#empty()} if the list is
* shorter than required for the given index.
return Optional.empty();
}
+ @Override
+ public String toString() {
+ return String.format("→ %s:%d", hostname, port);
+ }
+
/** Handles input and output for the connection. */
private class ConnectionHandler implements Closeable {
commandBuilder.append(parameter);
}
- logger.trace(String.format(">> %s", addEscapeCharacters(commandBuilder)));
+ logger.trace(String.format(">> %s", commandBuilder));
outputStream.write((commandBuilder.toString() + "\r\n").getBytes("UTF-8"));
outputStream.flush();
}
- private String addEscapeCharacters(StringBuilder commandBuilder) {
- StringBuilder escaped = new StringBuilder();
- for (char c : commandBuilder.toString().toCharArray()) {
- if (c < 32) {
- escaped.append("\\CTRL[").append((int) c).append("]");
- } else {
- escaped.append(c);
- }
- }
- return escaped.toString();
- }
-
/**
* Reads a line of reply from the connection.
*