You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/04/18 12:40:56 UTC
svn commit: r935328 -
/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java
Author: norman
Date: Sun Apr 18 10:40:56 2010
New Revision: 935328
URL: http://svn.apache.org/viewvc?rev=935328&view=rev
Log:
Better performing line handling
Modified:
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java
Modified: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java?rev=935328&r1=935327&r2=935328&view=diff
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java (original)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java Sun Apr 18 10:40:56 2010
@@ -21,6 +21,7 @@ package org.apache.james.socket.netty;
import org.apache.james.protocols.api.LineHandler;
import org.apache.james.protocols.api.ProtocolSession;
import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelUpstreamHandler;
@@ -44,22 +45,15 @@ public class LineHandlerUpstreamHandler<
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
Session pSession = (Session) attributes.get(ctx.getChannel());
+ // Copy buffer and add CRLF to it
ChannelBuffer buf = (ChannelBuffer) e.getMessage();
-
- byte[] line = new byte[buf.capacity()];
- buf.getBytes(0, line);
-
- // TODO: improve me!
- // thats not the most performant thing but it at least works for now
- // this should get improved later
- byte[] newLine = new byte[line.length +2];
- for (int i = 0; i < line.length; i++) {
- newLine[i] = line[i];
- }
- newLine[newLine.length -2] = '\r';
- newLine[newLine.length -1] = '\n';
-
- handler.onLine(pSession,newLine);
+ ChannelBuffer lineBuf = ChannelBuffers.buffer(buf.capacity() + 2);
+ lineBuf.writeBytes(buf);
+ lineBuf.writeInt('\r');
+ lineBuf.writeInt('\n');
+ byte[] lineBytes = new byte[lineBuf.capacity()];
+ lineBuf.getBytes(0, lineBytes);
+ handler.onLine(pSession, lineBytes);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org