Use StringUtil.simpleClassName(..) instead of Class.getSimpleName() where necessary

- Class.getSimpleName() doesn't render anonymous classes very well
- + some minor cleanup
This commit is contained in:
Trustin Lee 2013-11-04 19:42:33 +09:00
parent 5169376309
commit 26415b8f4c
37 changed files with 82 additions and 55 deletions

View File

@ -18,6 +18,7 @@ package io.netty.buffer;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ResourceLeakDetector; import io.netty.util.ResourceLeakDetector;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -1086,11 +1087,11 @@ public abstract class AbstractByteBuf extends ByteBuf {
@Override @Override
public String toString() { public String toString() {
if (refCnt() == 0) { if (refCnt() == 0) {
return getClass().getSimpleName() + "(freed)"; return StringUtil.simpleClassName(this) + "(freed)";
} }
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(ridx: "); buf.append("(ridx: ");
buf.append(readerIndex); buf.append(readerIndex);
buf.append(", widx: "); buf.append(", widx: ");

View File

@ -16,6 +16,7 @@
package io.netty.buffer; package io.netty.buffer;
import io.netty.util.IllegalReferenceCountException; import io.netty.util.IllegalReferenceCountException;
import io.netty.util.internal.StringUtil;
/** /**
* Default implementation of a {@link ByteBufHolder} that holds it's data in a {@link ByteBuf}. * Default implementation of a {@link ByteBufHolder} that holds it's data in a {@link ByteBuf}.
@ -79,6 +80,6 @@ public class DefaultByteBufHolder implements ByteBufHolder {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + '(' + content().toString() + ')'; return StringUtil.simpleClassName(this) + '(' + content().toString() + ')';
} }
} }

View File

@ -18,6 +18,7 @@ package io.netty.buffer;
import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.EmptyArrays;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -64,7 +65,7 @@ public final class EmptyByteBuf extends ByteBuf {
this.alloc = alloc; this.alloc = alloc;
this.order = order; this.order = order;
str = getClass().getSimpleName() + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE"); str = StringUtil.simpleClassName(this) + (order == ByteOrder.BIG_ENDIAN? "BE" : "LE");
} }
@Override @Override

View File

@ -16,6 +16,7 @@
package io.netty.buffer; package io.netty.buffer;
import io.netty.util.ResourceLeak; import io.netty.util.ResourceLeak;
import io.netty.util.internal.StringUtil;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -40,7 +41,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
public ReadOnlyByteBufferBuf(ByteBufAllocator allocator, ByteBuffer buffer) { public ReadOnlyByteBufferBuf(ByteBufAllocator allocator, ByteBuffer buffer) {
super(buffer.remaining()); super(buffer.remaining());
if (!buffer.isReadOnly()) { if (!buffer.isReadOnly()) {
throw new IllegalArgumentException("must be a readonly buffer: " + buffer.getClass().getSimpleName()); throw new IllegalArgumentException("must be a readonly buffer: " + StringUtil.simpleClassName(buffer));
} }
this.allocator = allocator; this.allocator = allocator;

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.internal.StringUtil;
/** /**
* The default {@link HttpContent} implementation. * The default {@link HttpContent} implementation.
@ -78,6 +79,6 @@ public class DefaultHttpContent extends DefaultHttpObject implements HttpContent
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')'; return StringUtil.simpleClassName(this) + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')';
} }
} }

View File

@ -58,7 +58,7 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(version: "); buf.append("(version: ");
buf.append(getProtocolVersion().text()); buf.append(getProtocolVersion().text());
buf.append(", keepAlive: "); buf.append(", keepAlive: ");

View File

@ -93,7 +93,7 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append(", decodeResult: "); buf.append(", decodeResult: ");
buf.append(getDecoderResult()); buf.append(getDecoderResult());
buf.append(')'); buf.append(')');

View File

@ -72,7 +72,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(decodeResult: "); buf.append("(decodeResult: ");
buf.append(getDecoderResult()); buf.append(getDecoderResult());
buf.append(')'); buf.append(')');

View File

@ -20,6 +20,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.FileRegion; import io.netty.channel.FileRegion;
import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -60,7 +61,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
if (msg instanceof HttpMessage) { if (msg instanceof HttpMessage) {
if (state != ST_INIT) { if (state != ST_INIT) {
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
@SuppressWarnings({ "unchecked", "CastConflictsWithInstanceof" }) @SuppressWarnings({ "unchecked", "CastConflictsWithInstanceof" })
@ -76,7 +77,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
} }
if (msg instanceof HttpContent || msg instanceof ByteBuf || msg instanceof FileRegion) { if (msg instanceof HttpContent || msg instanceof ByteBuf || msg instanceof FileRegion) {
if (state == ST_INIT) { if (state == ST_INIT) {
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
int contentLength = contentLength(msg); int contentLength = contentLength(msg);
@ -148,7 +149,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
if (msg instanceof FileRegion) { if (msg instanceof FileRegion) {
return ((FileRegion) msg).retain(); return ((FileRegion) msg).retain();
} }
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
private static int contentLength(Object msg) { private static int contentLength(Object msg) {
@ -161,7 +162,7 @@ public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageTo
if (msg instanceof FileRegion) { if (msg instanceof FileRegion) {
return (int) ((FileRegion) msg).count(); return (int) ((FileRegion) msg).count();
} }
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
private static void encodeHeaders(ByteBuf buf, HttpHeaders headers) { private static void encodeHeaders(ByteBuf buf, HttpHeaders headers) {

View File

@ -17,6 +17,7 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder; import io.netty.buffer.DefaultByteBufHolder;
import io.netty.util.internal.StringUtil;
/** /**
* Base class for web socket frames * Base class for web socket frames
@ -67,7 +68,7 @@ public abstract class WebSocketFrame extends DefaultByteBufHolder {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "(data: " + content().toString() + ')'; return StringUtil.simpleClassName(this) + "(data: " + content().toString() + ')';
} }
@Override @Override

View File

@ -122,7 +122,7 @@ public class DefaultSpdyDataFrame extends DefaultSpdyStreamFrame implements Spdy
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(last: "); buf.append("(last: ");
buf.append(isLast()); buf.append(isLast());
buf.append(')'); buf.append(')');

View File

@ -84,7 +84,7 @@ public class DefaultSpdyGoAwayFrame implements SpdyGoAwayFrame {
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
buf.append("--> Last-good-stream-ID = "); buf.append("--> Last-good-stream-ID = ");
buf.append(getLastGoodStreamId()); buf.append(getLastGoodStreamId());

View File

@ -80,7 +80,7 @@ public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(last: "); buf.append("(last: ");
buf.append(isLast()); buf.append(isLast());
buf.append(')'); buf.append(')');

View File

@ -47,7 +47,7 @@ public class DefaultSpdyPingFrame implements SpdyPingFrame {
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
buf.append("--> ID = "); buf.append("--> ID = ");
buf.append(getId()); buf.append(getId());

View File

@ -72,7 +72,7 @@ public class DefaultSpdyRstStreamFrame extends DefaultSpdyStreamFrame
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = "); buf.append("--> Stream-ID = ");
buf.append(getStreamId()); buf.append(getStreamId());

View File

@ -153,7 +153,7 @@ public class DefaultSpdySettingsFrame implements SpdySettingsFrame {
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
appendSettings(buf); appendSettings(buf);
buf.setLength(buf.length() - StringUtil.NEWLINE.length()); buf.setLength(buf.length() - StringUtil.NEWLINE.length());

View File

@ -53,7 +53,7 @@ public class DefaultSpdySynReplyFrame extends DefaultSpdyHeadersFrame
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(last: "); buf.append("(last: ");
buf.append(isLast()); buf.append(isLast());
buf.append(')'); buf.append(')');

View File

@ -104,7 +104,7 @@ public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append("(last: "); buf.append("(last: ");
buf.append(isLast()); buf.append(isLast());
buf.append("; unidirectional: "); buf.append("; unidirectional: ");

View File

@ -70,7 +70,7 @@ public class DefaultSpdyWindowUpdateFrame implements SpdyWindowUpdateFrame {
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
buf.append("--> Stream-ID = "); buf.append("--> Stream-ID = ");
buf.append(getStreamId()); buf.append(getStreamId());

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.memcache; package io.netty.handler.codec.memcache;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.internal.StringUtil;
/** /**
* The default {@link MemcacheContent} implementation. * The default {@link MemcacheContent} implementation.
@ -78,7 +79,8 @@ public class DefaultMemcacheContent extends DefaultMemcacheObject implements Mem
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')'; return StringUtil.simpleClassName(this) +
"(data: " + content() + ", getDecoderResult: " + getDecoderResult() + ')';
} }
} }

View File

@ -20,6 +20,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.FileRegion; import io.netty.channel.FileRegion;
import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.util.internal.StringUtil;
import java.util.List; import java.util.List;
@ -38,10 +39,12 @@ public abstract class MemcacheObjectEncoder<M extends MemcacheMessage> extends M
protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
if (msg instanceof MemcacheMessage) { if (msg instanceof MemcacheMessage) {
if (expectingMoreContent) { if (expectingMoreContent) {
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
out.add(encodeMessage(ctx, (M) msg)); @SuppressWarnings({ "unchecked", "CastConflictsWithInstanceof" })
final M m = (M) msg;
out.add(encodeMessage(ctx, m));
} }
if (msg instanceof MemcacheContent || msg instanceof ByteBuf || msg instanceof FileRegion) { if (msg instanceof MemcacheContent || msg instanceof ByteBuf || msg instanceof FileRegion) {
@ -86,7 +89,7 @@ public abstract class MemcacheObjectEncoder<M extends MemcacheMessage> extends M
if (msg instanceof FileRegion) { if (msg instanceof FileRegion) {
return (int) ((FileRegion) msg).count(); return (int) ((FileRegion) msg).count();
} }
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
/** /**
@ -105,7 +108,7 @@ public abstract class MemcacheObjectEncoder<M extends MemcacheMessage> extends M
if (msg instanceof FileRegion) { if (msg instanceof FileRegion) {
return ((FileRegion) msg).retain(); return ((FileRegion) msg).retain();
} }
throw new IllegalStateException("unexpected message type: " + msg.getClass().getSimpleName()); throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg));
} }
} }

View File

@ -21,6 +21,7 @@ import io.netty.buffer.ByteBufProcessor;
import io.netty.buffer.SwappedByteBuf; import io.netty.buffer.SwappedByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.Signal; import io.netty.util.Signal;
import io.netty.util.internal.StringUtil;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -788,7 +789,7 @@ final class ReplayingDecoderBuffer extends ByteBuf {
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + '(' + return StringUtil.simpleClassName(this) + '(' +
"ridx=" + "ridx=" +
readerIndex() + readerIndex() +
", " + ", " +

View File

@ -16,6 +16,7 @@
package io.netty.util; package io.netty.util;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -541,7 +542,7 @@ public class HashedWheelTimer implements Timer {
long remaining = deadline - currentTime + startTime; long remaining = deadline - currentTime + startTime;
StringBuilder buf = new StringBuilder(192); StringBuilder buf = new StringBuilder(192);
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append('('); buf.append('(');
buf.append("deadline: "); buf.append("deadline: ");

View File

@ -17,6 +17,7 @@
package io.netty.util; package io.netty.util;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -70,7 +71,7 @@ public final class ResourceLeakDetector<T> {
private long leakCheckCnt; private long leakCheckCnt;
public ResourceLeakDetector(Class<?> resourceType) { public ResourceLeakDetector(Class<?> resourceType) {
this(resourceType.getSimpleName()); this(StringUtil.simpleClassName(resourceType));
} }
public ResourceLeakDetector(String resourceType) { public ResourceLeakDetector(String resourceType) {
@ -78,7 +79,7 @@ public final class ResourceLeakDetector<T> {
} }
public ResourceLeakDetector(Class<?> resourceType, int samplingInterval, long maxActive) { public ResourceLeakDetector(Class<?> resourceType, int samplingInterval, long maxActive) {
this(resourceType.getSimpleName(), samplingInterval, maxActive); this(StringUtil.simpleClassName(resourceType), samplingInterval, maxActive);
} }
public ResourceLeakDetector(String resourceType, int samplingInterval, long maxActive) { public ResourceLeakDetector(String resourceType, int samplingInterval, long maxActive) {

View File

@ -15,6 +15,8 @@
*/ */
package io.netty.util.internal.logging; package io.netty.util.internal.logging;
import io.netty.util.internal.StringUtil;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
@ -183,6 +185,6 @@ public abstract class AbstractInternalLogger implements InternalLogger, Serializ
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + '(' + name() + ')'; return StringUtil.simpleClassName(this) + '(' + name() + ')';
} }
} }

View File

@ -22,6 +22,7 @@ import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.sctp.SctpTestPermutation.Factory; import io.netty.testsuite.transport.sctp.SctpTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.Rule;
@ -37,7 +38,7 @@ public abstract class AbstractSctpTest {
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO = private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
SctpTestPermutation.sctpChannel(); SctpTestPermutation.sctpChannel();
private static List<ByteBufAllocator> ALLOCATORS = SctpTestPermutation.allocator(); private static final List<ByteBufAllocator> ALLOCATORS = SctpTestPermutation.allocator();
@Rule @Rule
public final TestName testName = new TestName(); public final TestName testName = new TestName();
@ -65,7 +66,7 @@ public abstract class AbstractSctpTest {
cb.option(ChannelOption.ALLOCATOR, allocator); cb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s + %s) with %s", "Running: %s %d of %d (%s + %s) with %s",
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName())); testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator)));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);

View File

@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.Rule;
@ -54,7 +55,7 @@ public abstract class AbstractClientSocketTest {
cb.option(ChannelOption.ALLOCATOR, allocator); cb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d with %s", "Running: %s %d of %d with %s",
testName.getMethodName(), ++ i, COMBO.size(), allocator.getClass().getSimpleName())); testName.getMethodName(), ++ i, COMBO.size(), StringUtil.simpleClassName(allocator)));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), Bootstrap.class); testName.getMethodName(), Bootstrap.class);

View File

@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.Rule;
@ -60,7 +61,7 @@ public abstract class AbstractDatagramTest {
cb.option(ChannelOption.ALLOCATOR, allocator); cb.option(ChannelOption.ALLOCATOR, allocator);
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s + %s) with %s", "Running: %s %d of %d (%s + %s) with %s",
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName())); testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator)));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), Bootstrap.class, Bootstrap.class); testName.getMethodName(), Bootstrap.class, Bootstrap.class);

View File

@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.Rule;
@ -57,7 +58,7 @@ public abstract class AbstractServerSocketTest {
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s) with %s", "Running: %s %d of %d (%s) with %s",
testName.getMethodName(), ++ i, COMBO.size(), sb, allocator.getClass().getSimpleName())); testName.getMethodName(), ++ i, COMBO.size(), sb, StringUtil.simpleClassName(allocator)));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class); testName.getMethodName(), ServerBootstrap.class);

View File

@ -22,6 +22,7 @@ import io.netty.channel.ChannelOption;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory; import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetUtil; import io.netty.util.NetUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Rule; import org.junit.Rule;
@ -67,7 +68,7 @@ public abstract class AbstractSocketTest {
logger.info(String.format( logger.info(String.format(
"Running: %s %d of %d (%s + %s) with %s", "Running: %s %d of %d (%s + %s) with %s",
testName.getMethodName(), ++ i, COMBO.size(), sb, cb, allocator.getClass().getSimpleName())); testName.getMethodName(), ++ i, COMBO.size(), sb, cb, StringUtil.simpleClassName(allocator)));
try { try {
Method m = getClass().getDeclaredMethod( Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class); testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);

View File

@ -34,15 +34,15 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.internal.StringUtil;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import static io.netty.handler.codec.http.HttpHeaders.*; import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.GET; import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; import static io.netty.handler.codec.http.HttpVersion.*;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
/** /**
* Handles handshakes and messages * Handles handshakes and messages
@ -97,7 +97,7 @@ public class AutobahnServerHandler extends ChannelInboundHandlerAdapter {
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) { private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (logger.isLoggable(Level.FINE)) { if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format( logger.fine(String.format(
"Channel %s received %s", ctx.channel().hashCode(), frame.getClass().getSimpleName())); "Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame)));
} }
if (frame instanceof CloseWebSocketFrame) { if (frame instanceof CloseWebSocketFrame) {

View File

@ -25,6 +25,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import io.netty.util.internal.StringUtil;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -336,11 +337,11 @@ public abstract class AbstractBootstrap<B extends AbstractBootstrap<B, C>, C ext
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append('('); buf.append('(');
if (group != null) { if (group != null) {
buf.append("group: "); buf.append("group: ");
buf.append(group.getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(group));
buf.append(", "); buf.append(", ");
} }
if (localAddress != null) { if (localAddress != null) {

View File

@ -25,6 +25,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -92,6 +93,7 @@ public final class Bootstrap extends AbstractBootstrap<Bootstrap, Channel> {
return channelFactory; return channelFactory;
} }
@Override
Channel createChannel() { Channel createChannel() {
EventLoop eventLoop = group().next(); EventLoop eventLoop = group().next();
return channelFactory().newChannel(eventLoop); return channelFactory().newChannel(eventLoop);
@ -300,7 +302,7 @@ public final class Bootstrap extends AbstractBootstrap<Bootstrap, Channel> {
@Override @Override
public String toString() { public String toString() {
return clazz.getSimpleName() + ".class"; return StringUtil.simpleClassName(clazz) + ".class";
} }
} }
} }

View File

@ -29,6 +29,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -69,7 +70,7 @@ public final class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, Se
/** /**
* The {@link Class} which is used to create {@link Channel} instances from. * The {@link Class} which is used to create {@link Channel} instances from.
* You either use this or {@link #channelFactory(ChannelFactory)} if your * You either use this or {@link #channelFactory(ServerChannelFactory)} if your
* {@link Channel} implementation has no no-args constructor. * {@link Channel} implementation has no no-args constructor.
*/ */
public ServerBootstrap channel(Class<? extends ServerChannel> channelClass) { public ServerBootstrap channel(Class<? extends ServerChannel> channelClass) {
@ -98,6 +99,7 @@ public final class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, Se
return this; return this;
} }
@Override
Channel createChannel() { Channel createChannel() {
EventLoop eventLoop = group().next(); EventLoop eventLoop = group().next();
return channelFactory().newChannel(eventLoop, childGroup); return channelFactory().newChannel(eventLoop, childGroup);
@ -321,7 +323,7 @@ public final class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, Se
buf.append(", "); buf.append(", ");
if (childGroup != null) { if (childGroup != null) {
buf.append("childGroup: "); buf.append("childGroup: ");
buf.append(childGroup.getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(childGroup));
buf.append(", "); buf.append(", ");
} }
synchronized (childOptions) { synchronized (childOptions) {
@ -374,7 +376,7 @@ public final class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, Se
@Override @Override
public String toString() { public String toString() {
return clazz.getSimpleName() + ".class"; return StringUtil.simpleClassName(clazz) + ".class";
} }
} }
} }

View File

@ -700,7 +700,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(StringUtil.simpleClassName(this));
buf.append('{'); buf.append('{');
DefaultChannelHandlerContext ctx = head.next; DefaultChannelHandlerContext ctx = head.next;
for (;;) { for (;;) {

View File

@ -24,6 +24,7 @@ import io.netty.channel.ServerChannel;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
import io.netty.util.internal.StringUtil;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.ArrayList; import java.util.ArrayList;
@ -315,7 +316,6 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
@Override @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + return StringUtil.simpleClassName(this) + "(name: " + name() + ", size: " + size() + ')';
"(name: " + name() + ", size: " + size() + ')';
} }
} }

View File

@ -18,6 +18,7 @@ package io.netty.channel.local;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -32,8 +33,7 @@ final class LocalChannelRegistry {
throw new ChannelException("already bound"); throw new ChannelException("already bound");
} }
if (!(localAddress instanceof LocalAddress)) { if (!(localAddress instanceof LocalAddress)) {
throw new ChannelException( throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress));
"unsupported address type: " + localAddress.getClass().getSimpleName());
} }
LocalAddress addr = (LocalAddress) localAddress; LocalAddress addr = (LocalAddress) localAddress;