Author: norman Date: Mon Oct 17 06:10:10 2011 New Revision: 1185015 URL: http://svn.apache.org/viewvc?rev=1185015&view=rev Log: LineHandlerUpstreamHandler does create byte arrays with wrong size when copy data. See PROTOCOLS-42
Modified: 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/LineHandlerUpstreamHandler.java URL: http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/LineHandlerUpstreamHandler.java?rev=1185015&r1=1185014&r2=1185015&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 Oct 17 06:10:10 2011 @@ -48,10 +48,17 @@ public class LineHandlerUpstreamHandler< ChannelBuffer buf = (ChannelBuffer) e.getMessage(); byte[] line; if (buf.hasArray()) { - line = buf.array(); + if (buf.arrayOffset() == 0 && buf.readableBytes() == buf.capacity()) { + // we have no offset and the length is the same as the capacity. Its safe to reuse the array without copy it first + line = buf.array(); + } else { + // copy the ChannelBuffer to a byte array to process the LineHandler + line = new byte[buf.readableBytes()]; + buf.getBytes(0, line); + } } else { // copy the ChannelBuffer to a byte array to process the LineHandler - line = new byte[buf.capacity()]; + line = new byte[buf.readableBytes()]; buf.getBytes(0, line); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org