Author: norman
Date: Mon Nov 8 14:29:59 2010
New Revision: 1032583
URL: http://svn.apache.org/viewvc?rev=1032583&view=rev
Log:
Only copy ChannelBuffer to byte array if needed (PROTOCOLS-7)
Modified:
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/LineHandlerUpstreamHandler.java
Modified:
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java?rev=1032583&r1=1032582&r2=1032583&view=diff
==============================================================================
---
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java
(original)
+++
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java
Mon Nov 8 14:29:59 2010
@@ -85,14 +85,21 @@ public abstract class AbstractChannelUps
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
ProtocolSession pSession = (ProtocolSession)
attributes.get(ctx.getChannel());
LinkedList<LineHandler> lineHandlers =
chain.getHandlers(LineHandler.class);
-
- ChannelBuffer buf = (ChannelBuffer) e.getMessage();
- byte[] line = new byte[buf.capacity()];
- buf.getBytes(0, line);
+
if (lineHandlers.size() > 0) {
+
+ ChannelBuffer buf = (ChannelBuffer) e.getMessage();
+ byte[] line;
+
+ if (buf.hasArray()) {
+ line = buf.array();
+ } else {
+ // copy the ChannelBuffer to a byte array to process the
LineHandler
+ line = new byte[buf.capacity()];
+ buf.getBytes(0, line);
+ }
- // Maybe it would be better to use the ByteBuffer here
((LineHandler) lineHandlers.getLast()).onLine(pSession,line);
}
Modified:
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/LineHandlerUpstreamHandler.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/LineHandlerUpstreamHandler.java?rev=1032583&r1=1032582&r2=1032583&view=diff
==============================================================================
---
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/LineHandlerUpstreamHandler.java
(original)
+++
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/LineHandlerUpstreamHandler.java
Mon Nov 8 14:29:59 2010
@@ -45,10 +45,14 @@ public class LineHandlerUpstreamHandler<
Session pSession = (Session) attributes.get(ctx.getChannel());
ChannelBuffer buf = (ChannelBuffer) e.getMessage();
-
- // copy the ChannelBuffer to a byte array to process the LineHandler
- byte[] line = new byte[buf.capacity()];
- buf.getBytes(0, line);
+ byte[] line;
+ if (buf.hasArray()) {
+ line = buf.array();
+ } else {
+ // copy the ChannelBuffer to a byte array to process the
LineHandler
+ line = new byte[buf.capacity()];
+ buf.getBytes(0, line);
+ }
handler.onLine(pSession, line);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]