diff --git a/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java index 00654458f9..b67d3d1b97 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java @@ -1076,23 +1076,18 @@ public abstract class AbstractByteBuf extends ByteBuf { return StringUtil.simpleClassName(this) + "(freed)"; } - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append("(ridx: "); - buf.append(readerIndex); - buf.append(", widx: "); - buf.append(writerIndex); - buf.append(", cap: "); - buf.append(capacity()); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append("(ridx: ").append(readerIndex) + .append(", widx: ").append(writerIndex) + .append(", cap: ").append(capacity()); if (maxCapacity != Integer.MAX_VALUE) { - buf.append('/'); - buf.append(maxCapacity); + buf.append('/').append(maxCapacity); } ByteBuf unwrapped = unwrap(); if (unwrapped != null) { - buf.append(", unwrapped: "); - buf.append(unwrapped); + buf.append(", unwrapped: ").append(unwrapped); } buf.append(')'); return buf.toString(); diff --git a/buffer/src/main/java/io/netty/buffer/PoolArena.java b/buffer/src/main/java/io/netty/buffer/PoolArena.java index 6a5b6b972d..a9ae9ddc26 100644 --- a/buffer/src/main/java/io/netty/buffer/PoolArena.java +++ b/buffer/src/main/java/io/netty/buffer/PoolArena.java @@ -309,41 +309,41 @@ abstract class PoolArena { protected abstract void destroyChunk(PoolChunk chunk); public synchronized String toString() { - StringBuilder buf = new StringBuilder(); - buf.append("Chunk(s) at 0~25%:"); - buf.append(StringUtil.NEWLINE); - buf.append(qInit); - buf.append(StringUtil.NEWLINE); - buf.append("Chunk(s) at 0~50%:"); - buf.append(StringUtil.NEWLINE); - buf.append(q000); - buf.append(StringUtil.NEWLINE); - buf.append("Chunk(s) at 25~75%:"); - buf.append(StringUtil.NEWLINE); - buf.append(q025); - buf.append(StringUtil.NEWLINE); - buf.append("Chunk(s) at 50~100%:"); - buf.append(StringUtil.NEWLINE); - buf.append(q050); - buf.append(StringUtil.NEWLINE); - buf.append("Chunk(s) at 75~100%:"); - buf.append(StringUtil.NEWLINE); - buf.append(q075); - buf.append(StringUtil.NEWLINE); - buf.append("Chunk(s) at 100%:"); - buf.append(StringUtil.NEWLINE); - buf.append(q100); - buf.append(StringUtil.NEWLINE); - buf.append("tiny subpages:"); + StringBuilder buf = new StringBuilder() + .append("Chunk(s) at 0~25%:") + .append(StringUtil.NEWLINE) + .append(qInit) + .append(StringUtil.NEWLINE) + .append("Chunk(s) at 0~50%:") + .append(StringUtil.NEWLINE) + .append(q000) + .append(StringUtil.NEWLINE) + .append("Chunk(s) at 25~75%:") + .append(StringUtil.NEWLINE) + .append(q025) + .append(StringUtil.NEWLINE) + .append("Chunk(s) at 50~100%:") + .append(StringUtil.NEWLINE) + .append(q050) + .append(StringUtil.NEWLINE) + .append("Chunk(s) at 75~100%:") + .append(StringUtil.NEWLINE) + .append(q075) + .append(StringUtil.NEWLINE) + .append("Chunk(s) at 100%:") + .append(StringUtil.NEWLINE) + .append(q100) + .append(StringUtil.NEWLINE) + .append("tiny subpages:"); for (int i = 1; i < tinySubpagePools.length; i ++) { PoolSubpage head = tinySubpagePools[i]; if (head.next == head) { continue; } - buf.append(StringUtil.NEWLINE); - buf.append(i); - buf.append(": "); + buf.append(StringUtil.NEWLINE) + .append(i) + .append(": "); PoolSubpage s = head.next; for (;;) { buf.append(s); @@ -353,17 +353,17 @@ abstract class PoolArena { } } } - buf.append(StringUtil.NEWLINE); - buf.append("small subpages:"); + buf.append(StringUtil.NEWLINE) + .append("small subpages:"); for (int i = 1; i < smallSubpagePools.length; i ++) { PoolSubpage head = smallSubpagePools[i]; if (head.next == head) { continue; } - buf.append(StringUtil.NEWLINE); - buf.append(i); - buf.append(": "); + buf.append(StringUtil.NEWLINE) + .append(i) + .append(": "); PoolSubpage s = head.next; for (;;) { buf.append(s); diff --git a/buffer/src/main/java/io/netty/buffer/PoolChunk.java b/buffer/src/main/java/io/netty/buffer/PoolChunk.java index 0eb8ce11c2..06713988bc 100644 --- a/buffer/src/main/java/io/netty/buffer/PoolChunk.java +++ b/buffer/src/main/java/io/netty/buffer/PoolChunk.java @@ -416,16 +416,16 @@ final class PoolChunk { @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append("Chunk("); - buf.append(Integer.toHexString(System.identityHashCode(this))); - buf.append(": "); - buf.append(usage()); - buf.append("%, "); - buf.append(chunkSize - freeBytes); - buf.append('/'); - buf.append(chunkSize); - buf.append(')'); - return buf.toString(); + return new StringBuilder() + .append("Chunk(") + .append(Integer.toHexString(System.identityHashCode(this))) + .append(": ") + .append(usage()) + .append("%, ") + .append(chunkSize - freeBytes) + .append('/') + .append(chunkSize) + .append(')') + .toString(); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java index df6ec547c0..ea3150cb2d 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java @@ -308,26 +308,26 @@ public class DefaultCookie implements Cookie { @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(name()); - buf.append('='); - buf.append(value()); + StringBuilder buf = new StringBuilder() + .append(name()) + .append('=') + .append(value()); if (domain() != null) { - buf.append(", domain="); - buf.append(domain()); + buf.append(", domain=") + .append(domain()); } if (path() != null) { - buf.append(", path="); - buf.append(path()); + buf.append(", path=") + .append(path()); } if (comment() != null) { - buf.append(", comment="); - buf.append(comment()); + buf.append(", comment=") + .append(comment()); } if (maxAge() >= 0) { - buf.append(", maxAge="); - buf.append(maxAge()); - buf.append('s'); + buf.append(", maxAge=") + .append(maxAge()) + .append('s'); } if (isSecure()) { buf.append(", secure"); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java index 66428c0690..79628c56e9 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/DefaultHttpMessage.java @@ -79,14 +79,14 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append("(version: "); - buf.append(protocolVersion().text()); - buf.append(", keepAlive: "); - buf.append(HttpHeaderUtil.isKeepAlive(this)); - buf.append(')'); - buf.append(StringUtil.NEWLINE); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append("(version: ") + .append(protocolVersion().text()) + .append(", keepAlive: ") + .append(HttpHeaderUtil.isKeepAlive(this)) + .append(')') + .append(StringUtil.NEWLINE); appendHeaders(buf); // Remove the last newline. @@ -109,10 +109,10 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht void appendHeaders(StringBuilder buf, HttpHeaders headers) { for (Map.Entry e: headers) { - buf.append(e.getKey()); - buf.append(": "); - buf.append(e.getValue()); - buf.append(StringUtil.NEWLINE); + buf.append(e.getKey()) + .append(": ") + .append(e.getValue()) + .append(StringUtil.NEWLINE); } } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java index 79b956f7bc..bfddd3a086 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java @@ -520,9 +520,9 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { char firstChar = line.charAt(0); if (name != null && (firstChar == ' ' || firstChar == '\t')) { StringBuilder buf = new StringBuilder(value.length() + line.length() + 1); - buf.append(value); - buf.append(' '); - buf.append(line.toString().trim()); + buf.append(value) + .append(' ') + .append(line.toString().trim()); value = buf.toString(); } else { if (name != null) { @@ -588,8 +588,8 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder { String lineTrimmed = line.toString().trim(); CharSequence currentLastPos = current.get(lastPos); StringBuilder b = new StringBuilder(currentLastPos.length() + lineTrimmed.length()); - b.append(currentLastPos); - b.append(lineTrimmed); + b.append(currentLastPos) + .append(lineTrimmed); current.set(lastPos, b.toString()); } else { // Content-Length, Transfer-Encoding, or Trailer diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java index 5ff5af9c76..3d8fdabc82 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java @@ -60,9 +60,9 @@ public class HttpRequestEncoder extends HttpObjectEncoder { if (uri.lastIndexOf(SLASH, index) <= startIndex) { int len = uri.length(); StringBuilder sb = new StringBuilder(len + 1); - sb.append(uri, 0, index); - sb.append(SLASH); - sb.append(uri, index, len); + sb.append(uri, 0, index) + .append(SLASH) + .append(uri, index, len); uri = sb.toString(); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java index c2319bb02d..2228d99dd5 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseStatus.java @@ -576,11 +576,11 @@ public class HttpResponseStatus implements Comparable { @Override public String toString() { - StringBuilder buf = new StringBuilder(reasonPhrase.length() + 5); - buf.append(code); - buf.append(' '); - buf.append(reasonPhrase); - return buf.toString(); + return new StringBuilder(reasonPhrase.length() + 5) + .append(code) + .append(' ') + .append(reasonPhrase) + .toString(); } void encode(ByteBuf buf) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java index 88993216e7..a519a20e51 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java @@ -581,42 +581,42 @@ public class HttpPostRequestEncoder implements ChunkedInput { globalBodySize -= pastAttribute.size(); StringBuilder replacement = new StringBuilder( 139 + multipartDataBoundary.length() + multipartMixedBoundary.length() * 2 + - fileUpload.getFilename().length() + fileUpload.getName().length()); + fileUpload.getFilename().length() + fileUpload.getName().length()) - replacement.append("--"); - replacement.append(multipartDataBoundary); - replacement.append("\r\n"); + .append("--") + .append(multipartDataBoundary) + .append("\r\n") - replacement.append(HttpHeaderNames.CONTENT_DISPOSITION); - replacement.append(": "); - replacement.append(HttpHeaderValues.FORM_DATA); - replacement.append("; "); - replacement.append(HttpHeaderValues.NAME); - replacement.append("=\""); - replacement.append(fileUpload.getName()); - replacement.append("\"\r\n"); + .append(HttpHeaderNames.CONTENT_DISPOSITION) + .append(": ") + .append(HttpHeaderValues.FORM_DATA) + .append("; ") + .append(HttpHeaderValues.NAME) + .append("=\"") + .append(fileUpload.getName()) + .append("\"\r\n") - replacement.append(HttpHeaderNames.CONTENT_TYPE); - replacement.append(": "); - replacement.append(HttpHeaderValues.MULTIPART_MIXED); - replacement.append("; "); - replacement.append(HttpHeaderValues.BOUNDARY); - replacement.append('='); - replacement.append(multipartMixedBoundary); - replacement.append("\r\n\r\n"); + .append(HttpHeaderNames.CONTENT_TYPE) + .append(": ") + .append(HttpHeaderValues.MULTIPART_MIXED) + .append("; ") + .append(HttpHeaderValues.BOUNDARY) + .append('=') + .append(multipartMixedBoundary) + .append("\r\n\r\n") - replacement.append("--"); - replacement.append(multipartMixedBoundary); - replacement.append("\r\n"); + .append("--") + .append(multipartMixedBoundary) + .append("\r\n") - replacement.append(HttpHeaderNames.CONTENT_DISPOSITION); - replacement.append(": "); - replacement.append(HttpHeaderValues.ATTACHMENT); - replacement.append("; "); - replacement.append(HttpHeaderValues.FILENAME); - replacement.append("=\""); - replacement.append(fileUpload.getFilename()); - replacement.append("\"\r\n"); + .append(HttpHeaderNames.CONTENT_DISPOSITION) + .append(": ") + .append(HttpHeaderValues.ATTACHMENT) + .append("; ") + .append(HttpHeaderValues.FILENAME) + .append("=\"") + .append(fileUpload.getFilename()) + .append("\"\r\n"); pastAttribute.setValue(replacement.toString(), 1); pastAttribute.setValue("", 2); diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java index 46b2553cb5..85ca0dfc11 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyDataFrame.java @@ -133,16 +133,16 @@ public class DefaultSpdyDataFrame extends DefaultSpdyStreamFrame implements Spdy @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append("(last: "); - buf.append(isLast()); - buf.append(')'); - buf.append(StringUtil.NEWLINE); - buf.append("--> Stream-ID = "); - buf.append(streamId()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Size = "); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append("(last: ") + .append(isLast()) + .append(')') + .append(StringUtil.NEWLINE) + .append("--> Stream-ID = ") + .append(streamId()) + .append(StringUtil.NEWLINE) + .append("--> Size = "); if (refCnt() == 0) { buf.append("(freed)"); } else { diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java index 86f4ecc1cc..4d88875a6e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyGoAwayFrame.java @@ -83,14 +83,14 @@ public class DefaultSpdyGoAwayFrame implements SpdyGoAwayFrame { @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append(StringUtil.NEWLINE); - buf.append("--> Last-good-stream-ID = "); - buf.append(lastGoodStreamId()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Status: "); - buf.append(status()); - return buf.toString(); + return new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append(StringUtil.NEWLINE) + .append("--> Last-good-stream-ID = ") + .append(lastGoodStreamId()) + .append(StringUtil.NEWLINE) + .append("--> Status: ") + .append(status()) + .toString(); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java index e18be4cac7..a74934899e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyHeadersFrame.java @@ -79,17 +79,17 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append("(last: "); - buf.append(isLast()); - buf.append(')'); - buf.append(StringUtil.NEWLINE); - buf.append("--> Stream-ID = "); - buf.append(streamId()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Headers:"); - buf.append(StringUtil.NEWLINE); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append("(last: ") + .append(isLast()) + .append(')') + .append(StringUtil.NEWLINE) + .append("--> Stream-ID = ") + .append(streamId()) + .append(StringUtil.NEWLINE) + .append("--> Headers:") + .append(StringUtil.NEWLINE); appendHeaders(buf); // Remove the last newline. diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java index 2af2b72bdb..37c8a41398 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyPingFrame.java @@ -46,11 +46,11 @@ public class DefaultSpdyPingFrame implements SpdyPingFrame { @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append(StringUtil.NEWLINE); - buf.append("--> ID = "); - buf.append(id()); - return buf.toString(); + return new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append(StringUtil.NEWLINE) + .append("--> ID = ") + .append(id()) + .toString(); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java index a63f7db9da..a884295bdf 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyRstStreamFrame.java @@ -71,14 +71,14 @@ public class DefaultSpdyRstStreamFrame extends DefaultSpdyStreamFrame @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append(StringUtil.NEWLINE); - buf.append("--> Stream-ID = "); - buf.append(streamId()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Status: "); - buf.append(status()); - return buf.toString(); + return new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append(StringUtil.NEWLINE) + .append("--> Stream-ID = ") + .append(streamId()) + .append(StringUtil.NEWLINE) + .append("--> Status: ") + .append(status()) + .toString(); } } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java index c37e41cece..94483cbb47 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySettingsFrame.java @@ -152,10 +152,11 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame { @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append(StringUtil.NEWLINE); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append(StringUtil.NEWLINE); appendSettings(buf); + buf.setLength(buf.length() - StringUtil.NEWLINE.length()); return buf.toString(); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java index b9fafab008..0eacb9ee95 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynReplyFrame.java @@ -52,17 +52,17 @@ public class DefaultSpdySynReplyFrame extends DefaultSpdyHeadersFrame @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append("(last: "); - buf.append(isLast()); - buf.append(')'); - buf.append(StringUtil.NEWLINE); - buf.append("--> Stream-ID = "); - buf.append(streamId()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Headers:"); - buf.append(StringUtil.NEWLINE); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append("(last: ") + .append(isLast()) + .append(')') + .append(StringUtil.NEWLINE) + .append("--> Stream-ID = ") + .append(streamId()) + .append(StringUtil.NEWLINE) + .append("--> Headers:") + .append(StringUtil.NEWLINE); appendHeaders(buf); // Remove the last newline. diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java index 5f012903d1..a4495977e7 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdySynStreamFrame.java @@ -102,27 +102,27 @@ public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append("(last: "); - buf.append(isLast()); - buf.append("; unidirectional: "); - buf.append(isUnidirectional()); - buf.append(')'); - buf.append(StringUtil.NEWLINE); - buf.append("--> Stream-ID = "); - buf.append(streamId()); - buf.append(StringUtil.NEWLINE); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append("(last: ") + .append(isLast()) + .append("; unidirectional: ") + .append(isUnidirectional()) + .append(')') + .append(StringUtil.NEWLINE) + .append("--> Stream-ID = ") + .append(streamId()) + .append(StringUtil.NEWLINE); if (associatedStreamId != 0) { - buf.append("--> Associated-To-Stream-ID = "); - buf.append(associatedStreamId()); - buf.append(StringUtil.NEWLINE); + buf.append("--> Associated-To-Stream-ID = ") + .append(associatedStreamId()) + .append(StringUtil.NEWLINE); } - buf.append("--> Priority = "); - buf.append(priority()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Headers:"); - buf.append(StringUtil.NEWLINE); + buf.append("--> Priority = ") + .append(priority()) + .append(StringUtil.NEWLINE) + .append("--> Headers:") + .append(StringUtil.NEWLINE); appendHeaders(buf); // Remove the last newline. diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java index 1f30aa4e05..f14611bac6 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/DefaultSpdyWindowUpdateFrame.java @@ -69,14 +69,14 @@ public class DefaultSpdyWindowUpdateFrame implements SpdyWindowUpdateFrame { @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append(StringUtil.NEWLINE); - buf.append("--> Stream-ID = "); - buf.append(streamId()); - buf.append(StringUtil.NEWLINE); - buf.append("--> Delta-Window-Size = "); - buf.append(deltaWindowSize()); - return buf.toString(); + return new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append(StringUtil.NEWLINE) + .append("--> Stream-ID = ") + .append(streamId()) + .append(StringUtil.NEWLINE) + .append("--> Delta-Window-Size = ") + .append(deltaWindowSize()) + .toString(); } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionTestUtil.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionTestUtil.java index 5e171f3cce..e53f29220b 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionTestUtil.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionTestUtil.java @@ -79,7 +79,7 @@ public final class WebSocketExtensionTestUtil { @Override public void appendTo(StringBuffer buf) { - buf.append("WebSocketExtensionData with name=" + name); + buf.append("WebSocketExtensionData with name=").append(name); } @Override diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameLogger.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameLogger.java index 3d0b49da21..a6ce749220 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameLogger.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameLogger.java @@ -115,11 +115,12 @@ public class Http2FrameLogger extends ChannelHandlerAdapter { private void log(Direction direction, String format, Object... args) { if (logger.isEnabled(level)) { - StringBuilder b = new StringBuilder("\n----------------"); - b.append(direction.name()); - b.append("--------------------\n"); - b.append(String.format(format, args)); - b.append("\n------------------------------------"); + StringBuilder b = new StringBuilder(200); + b.append("\n----------------") + .append(direction.name()) + .append("--------------------\n") + .append(String.format(format, args)) + .append("\n------------------------------------"); logger.log(level, b.toString()); } } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java index 0dddd8b881..b9a8a7aa75 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/HttpUtil.java @@ -39,6 +39,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.regex.Pattern; /** * Provides utility methods and constants for the HTTP/2 to HTTP conversion @@ -81,6 +82,12 @@ public final class HttpUtil { */ public static final HttpResponseStatus OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE = HttpResponseStatus.OK; + /** + * This pattern will use to avoid compile it each time it is used + * when we need to replace some part of authority. + */ + private static final Pattern AUTHORITY_REPLACEMENT_PATTERN = Pattern.compile("^.*@"); + private HttpUtil() { } @@ -269,7 +276,7 @@ public final class HttpUtil { // The authority MUST NOT include the deprecated "userinfo" subcomponent value = hostUri.getAuthority(); if (value != null) { - out.authority(new AsciiString(value.replaceFirst("^.*@", ""))); + out.authority(new AsciiString(AUTHORITY_REPLACEMENT_PATTERN.matcher(value).replaceFirst(""))); } value = hostUri.getScheme(); if (value != null) { diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnAckVariableHeader.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnAckVariableHeader.java index 1ef1f29e28..7dfa309483 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnAckVariableHeader.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnAckVariableHeader.java @@ -35,9 +35,10 @@ public class MqttConnAckVariableHeader { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("connectReturnCode=").append(connectReturnCode); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("connectReturnCode=").append(connectReturnCode) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectPayload.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectPayload.java index a2a70af67e..c1d7f6a4dc 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectPayload.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectPayload.java @@ -64,13 +64,14 @@ public class MqttConnectPayload { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("clientIdentifier=").append(clientIdentifier); - builder.append(", willTopic=").append(willTopic); - builder.append(", willMessage=").append(willMessage); - builder.append(", userName=").append(userName); - builder.append(", password=").append(password); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("clientIdentifier=").append(clientIdentifier) + .append(", willTopic=").append(willTopic) + .append(", willMessage=").append(willMessage) + .append(", userName=").append(userName) + .append(", password=").append(password) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectVariableHeader.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectVariableHeader.java index 3e0266e7d0..991a54b6b0 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectVariableHeader.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttConnectVariableHeader.java @@ -92,16 +92,17 @@ public class MqttConnectVariableHeader { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("name=").append(name); - builder.append(", version=").append(version); - builder.append(", hasUserName=").append(hasUserName); - builder.append(", hasPassword=").append(hasPassword); - builder.append(", isWillRetain=").append(isWillRetain); - builder.append(", isWillFlag=").append(isWillFlag); - builder.append(", isCleanSession=").append(isCleanSession); - builder.append(", keepAliveTimeSeconds=").append(keepAliveTimeSeconds); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("name=").append(name) + .append(", version=").append(version) + .append(", hasUserName=").append(hasUserName) + .append(", hasPassword=").append(hasPassword) + .append(", isWillRetain=").append(isWillRetain) + .append(", isWillFlag=").append(isWillFlag) + .append(", isCleanSession=").append(isCleanSession) + .append(", keepAliveTimeSeconds=").append(keepAliveTimeSeconds) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttFixedHeader.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttFixedHeader.java index 79c1421d8e..812b9634ad 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttFixedHeader.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttFixedHeader.java @@ -65,13 +65,14 @@ public class MqttFixedHeader { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("messageType=").append(messageType); - builder.append(", isDup=").append(isDup); - builder.append(", qosLevel=").append(qosLevel); - builder.append(", isRetain=").append(isRetain); - builder.append(", remainingLength=").append(remainingLength); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("messageType=").append(messageType) + .append(", isDup=").append(isDup) + .append(", qosLevel=").append(qosLevel) + .append(", isRetain=").append(isRetain) + .append(", remainingLength=").append(remainingLength) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessage.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessage.java index c92aa015cf..9b1efa0b29 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessage.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessage.java @@ -70,11 +70,12 @@ public class MqttMessage { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("fixedHeader=").append(fixedHeader() != null ? fixedHeader().toString() : ""); - builder.append(", variableHeader=").append(variableHeader() != null ? variableHeader.toString() : ""); - builder.append(", payload=").append(payload() != null ? payload.toString() : ""); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("fixedHeader=").append(fixedHeader() != null ? fixedHeader().toString() : "") + .append(", variableHeader=").append(variableHeader() != null ? variableHeader.toString() : "") + .append(", payload=").append(payload() != null ? payload.toString() : "") + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessageIdVariableHeader.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessageIdVariableHeader.java index c4caf54468..c2e15935ca 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessageIdVariableHeader.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttMessageIdVariableHeader.java @@ -43,9 +43,10 @@ public final class MqttMessageIdVariableHeader { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("messageId=").append(messageId); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("messageId=").append(messageId) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttPublishVariableHeader.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttPublishVariableHeader.java index df7e744c07..d9cadb6fc5 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttPublishVariableHeader.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttPublishVariableHeader.java @@ -41,10 +41,11 @@ public class MqttPublishVariableHeader { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("topicName=").append(topicName); - builder.append(", messageId=").append(messageId); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("topicName=").append(topicName) + .append(", messageId=").append(messageId) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttSubAckPayload.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttSubAckPayload.java index dffb79ad6f..0e8c909ba4 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttSubAckPayload.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttSubAckPayload.java @@ -61,9 +61,10 @@ public class MqttSubAckPayload { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("grantedQoSLevels=").append(grantedQoSLevels); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("grantedQoSLevels=").append(grantedQoSLevels) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttTopicSubscription.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttTopicSubscription.java index 839b6f07c4..2ff1929085 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttTopicSubscription.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttTopicSubscription.java @@ -42,10 +42,11 @@ public class MqttTopicSubscription { @Override public String toString() { - StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); - builder.append("topicFilter=").append(topicFilter); - builder.append(", qualityOfService=").append(qualityOfService); - builder.append(']'); - return builder.toString(); + return new StringBuilder(StringUtil.simpleClassName(this)) + .append('[') + .append("topicFilter=").append(topicFilter) + .append(", qualityOfService=").append(qualityOfService) + .append(']') + .toString(); } } diff --git a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttUnsubscribePayload.java b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttUnsubscribePayload.java index b203760e07..068ae5cc7b 100644 --- a/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttUnsubscribePayload.java +++ b/codec-mqtt/src/main/java/io/netty/handler/codec/mqtt/MqttUnsubscribePayload.java @@ -40,10 +40,10 @@ public class MqttUnsubscribePayload { public String toString() { StringBuilder builder = new StringBuilder(StringUtil.simpleClassName(this)).append('['); for (int i = 0; i < topics.size() - 1; i++) { - builder.append("topicName = " + topics.get(i)).append(", "); + builder.append("topicName = ").append(topics.get(i)).append(", "); } - builder.append("topicName = " + topics.get(topics.size() - 1)); - builder.append(']'); + builder.append("topicName = ").append(topics.get(topics.size() - 1)) + .append(']'); return builder.toString(); } } diff --git a/codec/src/main/java/io/netty/handler/codec/DecoderResult.java b/codec/src/main/java/io/netty/handler/codec/DecoderResult.java index 054d3e86a6..f666a3b4f7 100644 --- a/codec/src/main/java/io/netty/handler/codec/DecoderResult.java +++ b/codec/src/main/java/io/netty/handler/codec/DecoderResult.java @@ -69,12 +69,11 @@ public class DecoderResult { } String cause = cause().toString(); - StringBuilder buf = new StringBuilder(cause.length() + 17); - buf.append("failure("); - buf.append(cause); - buf.append(')'); - - return buf.toString(); + return new StringBuilder(cause.length() + 17) + .append("failure(") + .append(cause) + .append(')') + .toString(); } else { return "unfinished"; } diff --git a/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java b/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java index b80a99f77c..9a4780c8b3 100644 --- a/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java +++ b/codec/src/main/java/io/netty/handler/codec/DefaultHeaders.java @@ -1366,11 +1366,11 @@ public class DefaultHeaders implements Headers { @Override public String toString() { - StringBuilder b = new StringBuilder(); - b.append(name); - b.append('='); - b.append(value); - return b.toString(); + return new StringBuilder() + .append(name) + .append('=') + .append(value) + .toString(); } } diff --git a/codec/src/main/java/io/netty/handler/codec/DefaultTextHeaders.java b/codec/src/main/java/io/netty/handler/codec/DefaultTextHeaders.java index d5fad92440..9be8c6fa8d 100644 --- a/codec/src/main/java/io/netty/handler/codec/DefaultTextHeaders.java +++ b/codec/src/main/java/io/netty/handler/codec/DefaultTextHeaders.java @@ -111,12 +111,12 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders 0) { - buf.append(remaining); - buf.append(" ns later"); + buf.append(remaining) + .append(" ns later"); } else if (remaining < 0) { - buf.append(-remaining); - buf.append(" ns ago"); + buf.append(-remaining) + .append(" ns ago"); } else { buf.append("now"); } @@ -610,10 +609,10 @@ public class HashedWheelTimer implements Timer { buf.append(", cancelled"); } - buf.append(", task: "); - buf.append(task()); - - return buf.append(')').toString(); + return buf.append(", task: ") + .append(task()) + .append(')') + .toString(); } } diff --git a/common/src/main/java/io/netty/util/ResourceLeakDetector.java b/common/src/main/java/io/netty/util/ResourceLeakDetector.java index 3b2e22a57f..03dc96a434 100644 --- a/common/src/main/java/io/netty/util/ResourceLeakDetector.java +++ b/common/src/main/java/io/netty/util/ResourceLeakDetector.java @@ -309,27 +309,27 @@ public final class ResourceLeakDetector { array = lastRecords.toArray(); } - StringBuilder buf = new StringBuilder(16384); - buf.append(NEWLINE); - buf.append("Recent access records: "); - buf.append(array.length); - buf.append(NEWLINE); + StringBuilder buf = new StringBuilder(16384) + .append(NEWLINE) + .append("Recent access records: ") + .append(array.length) + .append(NEWLINE); if (array.length > 0) { for (int i = array.length - 1; i >= 0; i --) { - buf.append('#'); - buf.append(i + 1); - buf.append(':'); - buf.append(NEWLINE); - buf.append(array[i]); + buf.append('#') + .append(i + 1) + .append(':') + .append(NEWLINE) + .append(array[i]); } } - buf.append("Created at:"); - buf.append(NEWLINE); - buf.append(creationRecord); - buf.setLength(buf.length() - NEWLINE.length()); + buf.append("Created at:") + .append(NEWLINE) + .append(creationRecord); + buf.setLength(buf.length() - NEWLINE.length()); return buf.toString(); } } diff --git a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java index cd45b97bd0..1a3ed0502d 100644 --- a/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java +++ b/common/src/main/java/io/netty/util/concurrent/DefaultPromise.java @@ -806,10 +806,10 @@ public class DefaultPromise extends AbstractFuture implements Promise { } protected StringBuilder toStringBuilder() { - StringBuilder buf = new StringBuilder(64); - buf.append(StringUtil.simpleClassName(this)); - buf.append('@'); - buf.append(Integer.toHexString(hashCode())); + StringBuilder buf = new StringBuilder(64) + .append(StringUtil.simpleClassName(this)) + .append('@') + .append(Integer.toHexString(hashCode())); Object result = this.result; if (result == SUCCESS) { @@ -817,9 +817,9 @@ public class DefaultPromise extends AbstractFuture implements Promise { } else if (result == UNCANCELLABLE) { buf.append("(uncancellable)"); } else if (result instanceof CauseHolder) { - buf.append("(failure("); - buf.append(((CauseHolder) result).cause); - buf.append(')'); + buf.append("(failure(") + .append(((CauseHolder) result).cause) + .append(')'); } else { buf.append("(incomplete)"); } diff --git a/common/src/main/java/io/netty/util/concurrent/PromiseTask.java b/common/src/main/java/io/netty/util/concurrent/PromiseTask.java index cf17103ea1..8cb23c7861 100644 --- a/common/src/main/java/io/netty/util/concurrent/PromiseTask.java +++ b/common/src/main/java/io/netty/util/concurrent/PromiseTask.java @@ -129,9 +129,9 @@ class PromiseTask extends DefaultPromise implements RunnableFuture { protected StringBuilder toStringBuilder() { StringBuilder buf = super.toStringBuilder(); buf.setCharAt(buf.length() - 1, ','); - buf.append(" task: "); - buf.append(task); - buf.append(')'); - return buf; + + return buf.append(" task: ") + .append(task) + .append(')'); } } diff --git a/common/src/main/java/io/netty/util/concurrent/ScheduledFutureTask.java b/common/src/main/java/io/netty/util/concurrent/ScheduledFutureTask.java index 7fd20a36b7..a72cd2cec9 100644 --- a/common/src/main/java/io/netty/util/concurrent/ScheduledFutureTask.java +++ b/common/src/main/java/io/netty/util/concurrent/ScheduledFutureTask.java @@ -153,14 +153,14 @@ final class ScheduledFutureTask extends PromiseTask implements ScheduledFu protected StringBuilder toStringBuilder() { StringBuilder buf = super.toStringBuilder(); buf.setCharAt(buf.length() - 1, ','); - buf.append(" id: "); - buf.append(id); - buf.append(", deadline: "); - buf.append(deadlineNanos); - buf.append(", period: "); - buf.append(periodNanos); - buf.append(')'); - return buf; + + return buf.append(" id: ") + .append(id) + .append(", deadline: ") + .append(deadlineNanos) + .append(", period: ") + .append(periodNanos) + .append(')'); } /** diff --git a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java index f30fd5c215..0b7283f284 100644 --- a/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java +++ b/example/src/main/java/io/netty/example/http/file/HttpStaticFileServerHandler.java @@ -240,7 +240,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler\r\n") + .append("") + .append("Listing of: ") + .append(dirPath) + .append("\r\n") - buf.append("\r\n"); - buf.append(""); - buf.append("Listing of: "); - buf.append(dirPath); - buf.append("\r\n"); + .append("

Listing of: ") + .append(dirPath) + .append("

\r\n") - buf.append("

Listing of: "); - buf.append(dirPath); - buf.append("

\r\n"); - - buf.append("
    "); - buf.append("
  • ..
  • \r\n"); + .append("\r\n"); diff --git a/example/src/main/java/io/netty/example/spdy/client/SpdyFrameLogger.java b/example/src/main/java/io/netty/example/spdy/client/SpdyFrameLogger.java index c7e0c4eb4d..3f2a2532d8 100644 --- a/example/src/main/java/io/netty/example/spdy/client/SpdyFrameLogger.java +++ b/example/src/main/java/io/netty/example/spdy/client/SpdyFrameLogger.java @@ -66,9 +66,13 @@ public class SpdyFrameLogger extends ChannelHandlerAdapter { private void log(SpdyFrame msg, Direction d) { if (logger.isEnabled(level)) { - StringBuilder b = new StringBuilder("\n----------------").append(d.name()).append("--------------------\n"); - b.append(msg); - b.append("\n------------------------------------"); + StringBuilder b = new StringBuilder(200) + .append("\n----------------") + .append(d.name()) + .append("--------------------\n") + .append(msg) + .append("\n------------------------------------"); + logger.log(level, b.toString()); } } diff --git a/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyConnectionEvent.java b/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyConnectionEvent.java index 73443d954e..2d923fb73f 100644 --- a/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyConnectionEvent.java +++ b/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyConnectionEvent.java @@ -88,17 +88,17 @@ public final class ProxyConnectionEvent { return strVal; } - StringBuilder buf = new StringBuilder(128); - buf.append(StringUtil.simpleClassName(this)); - buf.append('('); - buf.append(protocol); - buf.append(", "); - buf.append(authScheme); - buf.append(", "); - buf.append(proxyAddress); - buf.append(" => "); - buf.append(destinationAddress); - buf.append(')'); + StringBuilder buf = new StringBuilder(128) + .append(StringUtil.simpleClassName(this)) + .append('(') + .append(protocol) + .append(", ") + .append(authScheme) + .append(", ") + .append(proxyAddress) + .append(" => ") + .append(destinationAddress) + .append(')'); return strVal = buf.toString(); } diff --git a/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java b/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java index 0c0613515f..6ccc39d1fb 100644 --- a/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java +++ b/handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java @@ -365,18 +365,16 @@ public abstract class ProxyHandler extends ChannelHandlerAdapter { msg = ""; } - StringBuilder buf = new StringBuilder(128 + msg.length()); - - buf.append(protocol()); - buf.append(", "); - buf.append(authScheme()); - buf.append(", "); - buf.append(proxyAddress); - buf.append(" => "); - buf.append(destinationAddress); - if (msg.length() > 0) { - buf.append(", "); - buf.append(msg); + StringBuilder buf = new StringBuilder(128 + msg.length()) + .append(protocol()) + .append(", ") + .append(authScheme()) + .append(", ") + .append(proxyAddress) + .append(" => ") + .append(destinationAddress); + if (!msg.isEmpty()) { + buf.append(", ").append(msg); } return buf.toString(); diff --git a/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java b/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java index f867181a41..3c59ff24b4 100644 --- a/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java +++ b/handler/src/main/java/io/netty/handler/logging/LoggingHandler.java @@ -308,11 +308,11 @@ public class LoggingHandler extends ChannelHandlerAdapter { */ protected String format(ChannelHandlerContext ctx, String eventName) { String chStr = ctx.channel().toString(); - StringBuilder buf = new StringBuilder(chStr.length() + 1 + eventName.length()); - buf.append(chStr); - buf.append(' '); - buf.append(eventName); - return buf.toString(); + return new StringBuilder(chStr.length() + 1 + eventName.length()) + .append(chStr) + .append(' ') + .append(eventName) + .toString(); } /** @@ -391,8 +391,8 @@ public class LoggingHandler extends ChannelHandlerAdapter { StringBuilder buf = new StringBuilder( chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 2 + 10 + 1 + 2 + rows * 80); - buf.append(chStr).append(' ').append(eventName).append(": "); - buf.append(msgStr).append(", ").append(length).append('B'); + buf.append(chStr).append(' ').append(eventName).append(": ") + .append(msgStr).append(", ").append(length).append('B'); appendHexDump(buf, content); return buf.toString(); diff --git a/handler/src/test/java/io/netty/handler/logging/LoggingHandlerTest.java b/handler/src/test/java/io/netty/handler/logging/LoggingHandlerTest.java index 78e7fd5f35..811698a198 100644 --- a/handler/src/test/java/io/netty/handler/logging/LoggingHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/logging/LoggingHandlerTest.java @@ -302,10 +302,10 @@ public class LoggingHandlerTest { @Override public void appendTo(StringBuffer buffer) { - buffer.append("matchesLog("); - buffer.append("expected: \"" + expected); - buffer.append("\", got: \"" + actualMsg); - buffer.append("\")"); + buffer.append("matchesLog(") + .append("expected: \"").append(expected) + .append("\", got: \"").append(actualMsg) + .append("\")"); } } diff --git a/transport-udt/src/test/java/io/netty/test/udt/util/UnitHelp.java b/transport-udt/src/test/java/io/netty/test/udt/util/UnitHelp.java index c4e79371f9..62878f5d4d 100644 --- a/transport-udt/src/test/java/io/netty/test/udt/util/UnitHelp.java +++ b/transport-udt/src/test/java/io/netty/test/udt/util/UnitHelp.java @@ -191,11 +191,11 @@ public final class UnitHelp { * Display current OS/ARCH. */ public static void logOsArch() { - final StringBuilder text = new StringBuilder(1024); - text.append("\n\t"); - text.append(System.getProperty("os.name")); - text.append("\n\t"); - text.append(System.getProperty("os.arch")); + final StringBuilder text = new StringBuilder(1024) + .append("\n\t") + .append(System.getProperty("os.name")) + .append("\n\t") + .append(System.getProperty("os.arch")); log.info("\n\t[os/arch]{}", text); } diff --git a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java index baf22c7841..f7c04d9e73 100644 --- a/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/AbstractBootstrap.java @@ -406,42 +406,42 @@ public abstract class AbstractBootstrap, C ext @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append('('); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append('('); if (group != null) { - buf.append("group: "); - buf.append(StringUtil.simpleClassName(group)); - buf.append(", "); + buf.append("group: ") + .append(StringUtil.simpleClassName(group)) + .append(", "); } if (channelFactory != null) { - buf.append("channelFactory: "); - buf.append(channelFactory); - buf.append(", "); + buf.append("channelFactory: ") + .append(channelFactory) + .append(", "); } if (localAddress != null) { - buf.append("localAddress: "); - buf.append(localAddress); - buf.append(", "); + buf.append("localAddress: ") + .append(localAddress) + .append(", "); } synchronized (options) { if (!options.isEmpty()) { - buf.append("options: "); - buf.append(options); - buf.append(", "); + buf.append("options: ") + .append(options) + .append(", "); } } synchronized (attrs) { if (!attrs.isEmpty()) { - buf.append("attrs: "); - buf.append(attrs); - buf.append(", "); + buf.append("attrs: ") + .append(attrs) + .append(", "); } } if (handler != null) { - buf.append("handler: "); - buf.append(handler); - buf.append(", "); + buf.append("handler: ") + .append(handler) + .append(", "); } if (buf.charAt(buf.length() - 1) == '(') { buf.append(')'); diff --git a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java index 60306f4b55..1691cbe3c1 100644 --- a/transport/src/main/java/io/netty/bootstrap/Bootstrap.java +++ b/transport/src/main/java/io/netty/bootstrap/Bootstrap.java @@ -288,10 +288,10 @@ public class Bootstrap extends AbstractBootstrap { StringBuilder buf = new StringBuilder(super.toString()); buf.setLength(buf.length() - 1); - buf.append(", remoteAddress: "); - buf.append(remoteAddress); - buf.append(')'); - return buf.toString(); + return buf.append(", remoteAddress: ") + .append(remoteAddress) + .append(')') + .toString(); } } diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index 9b42f38822..ad2deae6c7 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -374,28 +374,28 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha dstAddr = localAddr; } - StringBuilder buf = new StringBuilder(96); - buf.append("[id: 0x"); - buf.append(id.asShortText()); - buf.append(", "); - buf.append(srcAddr); - buf.append(active? " => " : " :> "); - buf.append(dstAddr); - buf.append(']'); + StringBuilder buf = new StringBuilder(96) + .append("[id: 0x") + .append(id.asShortText()) + .append(", ") + .append(srcAddr) + .append(active? " => " : " :> ") + .append(dstAddr) + .append(']'); strVal = buf.toString(); } else if (localAddr != null) { - StringBuilder buf = new StringBuilder(64); - buf.append("[id: 0x"); - buf.append(id.asShortText()); - buf.append(", "); - buf.append(localAddr); - buf.append(']'); + StringBuilder buf = new StringBuilder(64) + .append("[id: 0x") + .append(id.asShortText()) + .append(", ") + .append(localAddr) + .append(']'); strVal = buf.toString(); } else { - StringBuilder buf = new StringBuilder(16); - buf.append("[id: 0x"); - buf.append(id.asShortText()); - buf.append(']'); + StringBuilder buf = new StringBuilder(16) + .append("[id: 0x") + .append(id.asShortText()) + .append(']'); strVal = buf.toString(); } diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java index 46425302e6..4dc241f7cd 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java @@ -811,20 +811,20 @@ final class DefaultChannelPipeline implements ChannelPipeline { */ @Override public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append(StringUtil.simpleClassName(this)); - buf.append('{'); + StringBuilder buf = new StringBuilder() + .append(StringUtil.simpleClassName(this)) + .append('{'); AbstractChannelHandlerContext ctx = head.next; for (;;) { if (ctx == tail) { break; } - buf.append('('); - buf.append(ctx.name()); - buf.append(" = "); - buf.append(ctx.handler().getClass().getName()); - buf.append(')'); + buf.append('(') + .append(ctx.name()) + .append(" = ") + .append(ctx.handler().getClass().getName()) + .append(')'); ctx = ctx.next; if (ctx == tail) {