diff --git a/codec/src/main/java/io/netty/handler/codec/LengthFieldPrepender.java b/codec/src/main/java/io/netty/handler/codec/LengthFieldPrepender.java index a2cca5b0ee..397549b887 100644 --- a/codec/src/main/java/io/netty/handler/codec/LengthFieldPrepender.java +++ b/codec/src/main/java/io/netty/handler/codec/LengthFieldPrepender.java @@ -128,13 +128,12 @@ public class LengthFieldPrepender extends MessageToByteEncoder { } @Override - protected void encode( - ChannelHandlerContext ctx, - ByteBuf msg, ByteBuf out) throws Exception { + protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { - int length = (lengthIncludesLengthFieldLength? - msg.readableBytes() + lengthFieldLength : msg.readableBytes()) + - lengthAdjustment; + int length = msg.readableBytes() + lengthAdjustment; + if (lengthIncludesLengthFieldLength) { + length += lengthFieldLength; + } if (length < 0) { throw new IllegalArgumentException( diff --git a/codec/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java b/codec/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java index ff6530cbd1..16bfa998ab 100644 --- a/codec/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java +++ b/codec/src/test/java/io/netty/handler/codec/frame/LengthFieldPrependerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 The Netty Project + * Copyright 2013 The Netty Project * * The Netty Project licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance @@ -23,11 +23,9 @@ import io.netty.util.CharsetUtil; import org.junit.Before; import org.junit.Test; -import static io.netty.buffer.Unpooled.copiedBuffer; -import static io.netty.buffer.Unpooled.wrappedBuffer; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static io.netty.buffer.Unpooled.*; +import static org.hamcrest.core.Is.*; +import static org.junit.Assert.*; public class LengthFieldPrependerTest {