Skip to content

Commit 5df3898

Browse files
committed
Fix decodeNonOptimized, close AsyncHttpClient#1305
1 parent bd263b2 commit 5df3898

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

netty-utils/src/main/java/org/asynchttpclient/netty/util/ByteBufUtils.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import static java.nio.charset.StandardCharsets.*;
1717
import io.netty.buffer.ByteBuf;
18-
import io.netty.buffer.CompositeByteBuf;
1918
import io.netty.buffer.Unpooled;
2019

2120
import java.nio.charset.CharacterCodingException;
@@ -35,22 +34,21 @@ public static String byteBuf2String(Charset charset, ByteBuf buf) throws Charact
3534
}
3635

3736
public static String decodeNonOptimized(Charset charset, ByteBuf... bufs) {
38-
39-
CompositeByteBuf composite = Unpooled.compositeBuffer(bufs.length);
4037

41-
try {
42-
for (ByteBuf buf : bufs) {
43-
buf.retain();
44-
composite.addComponent(buf);
45-
}
38+
for (ByteBuf buf : bufs) {
39+
buf.retain();
40+
}
4641

42+
ByteBuf composite = Unpooled.wrappedBuffer(bufs);
43+
44+
try {
4745
return composite.toString(charset);
4846

4947
} finally {
5048
composite.release();
5149
}
5250
}
53-
51+
5452
public static String byteBuf2String(Charset charset, ByteBuf... bufs) throws CharacterCodingException {
5553
if (charset.equals(UTF_8) || charset.equals(US_ASCII)) {
5654
return Utf8ByteBufCharsetDecoder.decodeUtf8(bufs);

0 commit comments

Comments
 (0)