Chris Thunes avatar Chris Thunes committed 0e2c677

A little cleanup

Comments (0)

Files changed (3)

brewtab-irc/src/main/java/com/brewtab/irc/IRCClient.java

      *            The address to connect to
      */
     public IRCClient(InetSocketAddress address) {
-        this.channelFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),
-                Executors.newCachedThreadPool());
+        this.channelFactory = new NioClientSocketChannelFactory(
+            Executors.newCachedThreadPool(),
+            Executors.newCachedThreadPool());
+
         this.bootstrap = new ClientBootstrap(this.channelFactory);
         this.channelHandler = null;
         this.pipelineFactory = new IRCChannelPipelineFactory(this);

brewtab-irc/src/main/java/com/brewtab/irc/protocol/IRCMessageDecoder.java

     @Override
     protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) {
         String message = (String) msg;
+
         try {
             return IRCMessage.fromString(message);
         } catch (IRCInvalidMessageException e) {
-            log.warn("Received unknown/invalid message", e);
+            log.warn("Received unknown/invalid message: {}", e.getMessage());
             return null;
         }
     }

brewtab-irc/src/main/java/com/brewtab/irc/protocol/IRCMessageEncoder.java

  * @author Christopher Thunes <cthunes@brewtab.com>
  */
 public class IRCMessageEncoder extends OneToOneEncoder {
-    @Override
-    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
-        if (msg instanceof IRCMessage) {
-            IRCMessage message = (IRCMessage) msg;
-            return message.toString();
-        } else if (msg instanceof IRCMessage[]) {
-            IRCMessage[] messages = (IRCMessage[]) msg;
-            StringBuffer buffer = new StringBuffer();
+    private String encodeMessage(IRCMessage message) {
+        return message.toString();
+    }
 
-            for (IRCMessage message : messages) {
-                buffer.append(message.toString());
-            }
+    private String encodeMessages(IRCMessage[] messages) {
+        StringBuilder sb = new StringBuilder();
+
+        for (IRCMessage message : messages) {
+            sb.append(encodeMessage(message));
+        }
 
-            return buffer.toString();
+        return sb.toString();
+    }
+
+    @Override
+    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
+        if (IRCMessage.class.isAssignableFrom(msg.getClass())) {
+            return encodeMessage((IRCMessage) msg);
+        } else if (IRCMessage[].class.isAssignableFrom(msg.getClass())) {
+            return encodeMessages((IRCMessage[]) msg);
         } else {
             throw new IllegalArgumentException("msg must be one of IRCMessage or IRCMessage[]");
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.