Simpler toString() for ByteBufAllocators

This commit is contained in:
Trustin Lee 2013-11-08 17:53:57 +09:00
parent 4c7fa950cc
commit 9125977692
2 changed files with 24 additions and 17 deletions

View File

@ -17,6 +17,7 @@
package io.netty.buffer;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
/**
* Skeletal {@link ByteBufAllocator} implementation to extend.
@ -188,4 +189,9 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
* Create a direct {@link ByteBuf} with the given initialCapacity and maxCapacity.
*/
protected abstract ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity);
@Override
public String toString() {
return StringUtil.simpleClassName(this) + "(directByDefault: " + directByDefault + ')';
}
}

View File

@ -17,7 +17,6 @@
package io.netty.buffer;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -245,20 +244,22 @@ public class PooledByteBufAllocator extends AbstractByteBufAllocator {
return directArenas != null;
}
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(heapArenas.length);
buf.append(" heap arena(s):");
buf.append(StringUtil.NEWLINE);
for (PoolArena<byte[]> a: heapArenas) {
buf.append(a);
}
buf.append(directArenas.length);
buf.append(" direct arena(s):");
buf.append(StringUtil.NEWLINE);
for (PoolArena<ByteBuffer> a: directArenas) {
buf.append(a);
}
return buf.toString();
}
// Too noisy at the moment.
//
// public String toString() {
// StringBuilder buf = new StringBuilder();
// buf.append(heapArenas.length);
// buf.append(" heap arena(s):");
// buf.append(StringUtil.NEWLINE);
// for (PoolArena<byte[]> a: heapArenas) {
// buf.append(a);
// }
// buf.append(directArenas.length);
// buf.append(" direct arena(s):");
// buf.append(StringUtil.NEWLINE);
// for (PoolArena<ByteBuffer> a: directArenas) {
// buf.append(a);
// }
// return buf.toString();
// }
}