Skip to content

Commit

Permalink
Simpler toString() for ByteBufAllocators
Browse files Browse the repository at this point in the history
  • Loading branch information
trustin committed Nov 8, 2013
1 parent 11f95c7 commit ba3bc0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -188,4 +189,9 @@ private static void validate(int initialCapacity, int maxCapacity) {
* 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 + ')';
}
}
35 changes: 18 additions & 17 deletions buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,20 +244,22 @@ public boolean isDirectBufferPooled() {
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();
// }
}

0 comments on commit ba3bc0c

Please sign in to comment.