Rename ByteBufUtil to BufUtil and move ChannelHandlerUtil.freeMessage() there / Remove ChannelHandlerUtil

This commit is contained in:
Trustin Lee 2013-02-08 23:23:26 +09:00
parent 0746199ca4
commit affd514b8c
13 changed files with 100 additions and 124 deletions

View File

@ -895,17 +895,17 @@ public abstract class AbstractByteBuf implements ByteBuf {
nioBuffer.flip();
}
return ByteBufUtil.decodeString(nioBuffer, charset);
return BufUtil.decodeString(nioBuffer, charset);
}
@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
return ByteBufUtil.indexOf(this, fromIndex, toIndex, value);
return BufUtil.indexOf(this, fromIndex, toIndex, value);
}
@Override
public int indexOf(int fromIndex, int toIndex, ByteBufIndexFinder indexFinder) {
return ByteBufUtil.indexOf(this, fromIndex, toIndex, indexFinder);
return BufUtil.indexOf(this, fromIndex, toIndex, indexFinder);
}
@Override
@ -951,7 +951,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
@Override
public int hashCode() {
return ByteBufUtil.hashCode(this);
return BufUtil.hashCode(this);
}
@Override
@ -960,14 +960,14 @@ public abstract class AbstractByteBuf implements ByteBuf {
return true;
}
if (o instanceof ByteBuf) {
return ByteBufUtil.equals(this, (ByteBuf) o);
return BufUtil.equals(this, (ByteBuf) o);
}
return false;
}
@Override
public int compareTo(ByteBuf that) {
return ByteBufUtil.compare(this, that);
return BufUtil.compare(this, that);
}
@Override

View File

@ -27,9 +27,10 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
/**
* Utility class for operate on a {@link ByteBuf}
* A collection of utility methods that is related with handling {@link ByteBuf}, {@link MessageBuf}, and their
* elements.
*/
public final class ByteBufUtil {
public final class BufUtil {
private static final char[] HEXDUMP_TABLE = new char[256 * 4];
@ -41,6 +42,21 @@ public final class ByteBufUtil {
}
}
/**
* Try to call {@link Freeable#free()} if the specified message implements {@link Freeable}. If the specified
* message doesn't implement {@link Freeable}, this method does nothing.
*/
public static void free(Object msg) {
if (msg instanceof Freeable) {
try {
((Freeable) msg).free();
} catch (UnsupportedOperationException e) {
// This can happen for derived buffers
// TODO: Think about this
}
}
}
/**
* Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
* of the specified buffer's readable bytes.
@ -370,5 +386,5 @@ public final class ByteBufUtil {
return dst.flip().toString();
}
private ByteBufUtil() { }
private BufUtil() { }
}

View File

@ -245,7 +245,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public short getShort(int index) {
return ByteBufUtil.swapShort(buf.getShort(index));
return BufUtil.swapShort(buf.getShort(index));
}
@Override
@ -255,7 +255,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public int getMedium(int index) {
return ByteBufUtil.swapMedium(buf.getMedium(index));
return BufUtil.swapMedium(buf.getMedium(index));
}
@Override
@ -265,7 +265,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public int getInt(int index) {
return ByteBufUtil.swapInt(buf.getInt(index));
return BufUtil.swapInt(buf.getInt(index));
}
@Override
@ -275,7 +275,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public long getLong(int index) {
return ByteBufUtil.swapLong(buf.getLong(index));
return BufUtil.swapLong(buf.getLong(index));
}
@Override
@ -354,25 +354,25 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public ByteBuf setShort(int index, int value) {
buf.setShort(index, ByteBufUtil.swapShort((short) value));
buf.setShort(index, BufUtil.swapShort((short) value));
return this;
}
@Override
public ByteBuf setMedium(int index, int value) {
buf.setMedium(index, ByteBufUtil.swapMedium(value));
buf.setMedium(index, BufUtil.swapMedium(value));
return this;
}
@Override
public ByteBuf setInt(int index, int value) {
buf.setInt(index, ByteBufUtil.swapInt(value));
buf.setInt(index, BufUtil.swapInt(value));
return this;
}
@Override
public ByteBuf setLong(int index, long value) {
buf.setLong(index, ByteBufUtil.swapLong(value));
buf.setLong(index, BufUtil.swapLong(value));
return this;
}
@ -463,7 +463,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public short readShort() {
return ByteBufUtil.swapShort(buf.readShort());
return BufUtil.swapShort(buf.readShort());
}
@Override
@ -473,7 +473,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public int readMedium() {
return ByteBufUtil.swapMedium(buf.readMedium());
return BufUtil.swapMedium(buf.readMedium());
}
@Override
@ -483,7 +483,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public int readInt() {
return ByteBufUtil.swapInt(buf.readInt());
return BufUtil.swapInt(buf.readInt());
}
@Override
@ -493,7 +493,7 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public long readLong() {
return ByteBufUtil.swapLong(buf.readLong());
return BufUtil.swapLong(buf.readLong());
}
@Override
@ -588,25 +588,25 @@ public final class SwappedByteBuf implements ByteBuf {
@Override
public ByteBuf writeShort(int value) {
buf.writeShort(ByteBufUtil.swapShort((short) value));
buf.writeShort(BufUtil.swapShort((short) value));
return this;
}
@Override
public ByteBuf writeMedium(int value) {
buf.writeMedium(ByteBufUtil.swapMedium(value));
buf.writeMedium(BufUtil.swapMedium(value));
return this;
}
@Override
public ByteBuf writeInt(int value) {
buf.writeInt(ByteBufUtil.swapInt(value));
buf.writeInt(BufUtil.swapInt(value));
return this;
}
@Override
public ByteBuf writeLong(long value) {
buf.writeLong(ByteBufUtil.swapLong(value));
buf.writeLong(BufUtil.swapLong(value));
return this;
}
@ -836,14 +836,14 @@ public final class SwappedByteBuf implements ByteBuf {
return true;
}
if (obj instanceof ByteBuf) {
return ByteBufUtil.equals(this, (ByteBuf) obj);
return BufUtil.equals(this, (ByteBuf) obj);
}
return false;
}
@Override
public int compareTo(ByteBuf buffer) {
return ByteBufUtil.compare(this, buffer);
return BufUtil.compare(this, buffer);
}
@Override

View File

@ -843,7 +843,7 @@ public final class Unpooled {
}
private static ByteBuf copiedBuffer(CharBuffer buffer, Charset charset) {
ByteBuffer dst = ByteBufUtil.encodeString(buffer, charset);
ByteBuffer dst = BufUtil.encodeString(buffer, charset);
ByteBuf result = wrappedBuffer(dst.array());
result.writerIndex(dst.remaining());
return result;

View File

@ -140,20 +140,20 @@ public abstract class AbstractCompositeByteBufTest extends
a.writerIndex(a.writerIndex() + 1);
b.writerIndex(b.writerIndex() + 1);
assertEquals(a.writerIndex(), b.writerIndex());
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// now discard
a.discardReadBytes();
b.discardReadBytes();
assertEquals(a.readerIndex(), b.readerIndex());
assertEquals(a.writerIndex(), b.writerIndex());
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
a.resetReaderIndex();
b.resetReaderIndex();
assertEquals(a.readerIndex(), b.readerIndex());
a.resetWriterIndex();
b.resetWriterIndex();
assertEquals(a.writerIndex(), b.writerIndex());
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
}
@Test
@ -228,57 +228,57 @@ public abstract class AbstractCompositeByteBufTest extends
a = wrappedBuffer(new byte[] { 1 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 1 }).order(order),
wrappedBuffer(new byte[] { 2 }).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Same content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 1 }).order(order),
wrappedBuffer(new byte[] { 2 }).order(order),
wrappedBuffer(new byte[] { 3 }).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Same content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 2).order(order),
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Different content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2 }).order(order),
wrappedBuffer(new byte[] { 4 }).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Different content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 2).order(order),
wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Same content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3 }).order(order),
wrappedBuffer(new byte[] { 4, 5, 6 }).order(order),
wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Same content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5).order(order),
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Different content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 1, 2, 3, 4, 6 }).order(order),
wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Different content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
b = wrappedBuffer(wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 5).order(order),
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
}
@Test
@ -334,7 +334,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 1);
b.writeBytes(
wrappedBuffer(new byte[] { 2 }).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Same content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
@ -344,7 +344,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writeBytes(
wrappedBuffer(new byte[] { 2 }).order(order));
b.writeBytes(wrappedBuffer(new byte[] { 3 }).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Same content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
@ -353,7 +353,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 1);
b.writeBytes(
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 3, 1).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Different content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
@ -362,7 +362,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 1);
b.writeBytes(
wrappedBuffer(new byte[] { 4 }).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Different content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 }).order(order);
@ -371,7 +371,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 1);
b.writeBytes(
wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 3, 1).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Same content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
@ -382,7 +382,7 @@ public abstract class AbstractCompositeByteBufTest extends
wrappedBuffer(new byte[] { 4, 5, 6 }).order(order));
b.writeBytes(
wrappedBuffer(new byte[] { 7, 8, 9, 10 }).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Same content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
@ -391,7 +391,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 5);
b.writeBytes(
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Different content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
@ -400,7 +400,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 5);
b.writeBytes(
wrappedBuffer(new byte[] { 7, 8, 5, 9, 10 }).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Different content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).order(order);
@ -409,7 +409,7 @@ public abstract class AbstractCompositeByteBufTest extends
b.writerIndex(b.writerIndex() - 5);
b.writeBytes(
wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 6, 5).order(order));
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
}
@Test

View File

@ -70,7 +70,7 @@ public class UnpooledTest {
for (Entry<byte[], Integer> e: map.entrySet()) {
assertEquals(
e.getValue().intValue(),
ByteBufUtil.hashCode(wrappedBuffer(e.getKey())));
BufUtil.hashCode(wrappedBuffer(e.getKey())));
}
}
@ -81,47 +81,47 @@ public class UnpooledTest {
// Different length.
a = wrappedBuffer(new byte[] { 1 });
b = wrappedBuffer(new byte[] { 1, 2 });
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Same content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 1, 2, 3 });
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Same content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4 }, 1, 3);
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Different content, same firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 1, 2, 4 });
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Different content, different firstIndex, short length.
a = wrappedBuffer(new byte[] { 1, 2, 3 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 4, 5 }, 1, 3);
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Same content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Same content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10);
assertTrue(ByteBufUtil.equals(a, b));
assertTrue(BufUtil.equals(a, b));
// Different content, same firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 1, 2, 3, 4, 6, 7, 8, 5, 9, 10 });
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
// Different content, different firstIndex, long length.
a = wrappedBuffer(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
b = wrappedBuffer(new byte[] { 0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11 }, 1, 10);
assertFalse(ByteBufUtil.equals(a, b));
assertFalse(BufUtil.equals(a, b));
}
@Test
@ -147,11 +147,11 @@ public class UnpooledTest {
for (int i = 0; i < expected.size(); i ++) {
for (int j = 0; j < expected.size(); j ++) {
if (i == j) {
assertEquals(0, ByteBufUtil.compare(expected.get(i), expected.get(j)));
assertEquals(0, BufUtil.compare(expected.get(i), expected.get(j)));
} else if (i < j) {
assertTrue(ByteBufUtil.compare(expected.get(i), expected.get(j)) < 0);
assertTrue(BufUtil.compare(expected.get(i), expected.get(j)) < 0);
} else {
assertTrue(ByteBufUtil.compare(expected.get(i), expected.get(j)) > 0);
assertTrue(BufUtil.compare(expected.get(i), expected.get(j)) > 0);
}
}
}
@ -196,12 +196,12 @@ public class UnpooledTest {
@Test
public void testCompare2() {
assertTrue(ByteBufUtil.compare(
assertTrue(BufUtil.compare(
wrappedBuffer(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}),
wrappedBuffer(new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}))
> 0);
assertTrue(ByteBufUtil.compare(
assertTrue(BufUtil.compare(
wrappedBuffer(new byte[]{(byte) 0xFF}),
wrappedBuffer(new byte[]{(byte) 0x00}))
> 0);
@ -302,15 +302,15 @@ public class UnpooledTest {
@Test
public void testHexDump() {
assertEquals("", ByteBufUtil.hexDump(EMPTY_BUFFER));
assertEquals("", BufUtil.hexDump(EMPTY_BUFFER));
assertEquals("123456", ByteBufUtil.hexDump(wrappedBuffer(
new byte[] {
assertEquals("123456", BufUtil.hexDump(wrappedBuffer(
new byte[]{
0x12, 0x34, 0x56
})));
assertEquals("1234567890abcdef", ByteBufUtil.hexDump(wrappedBuffer(
new byte[] {
assertEquals("1234567890abcdef", BufUtil.hexDump(wrappedBuffer(
new byte[]{
0x12, 0x34, 0x56, 0x78,
(byte) 0x90, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF
})));
@ -318,8 +318,8 @@ public class UnpooledTest {
@Test
public void testSwapMedium() {
assertEquals(0x563412, ByteBufUtil.swapMedium(0x123456));
assertEquals(0x80, ByteBufUtil.swapMedium(0x800000));
assertEquals(0x563412, BufUtil.swapMedium(0x123456));
assertEquals(0x80, BufUtil.swapMedium(0x800000));
}
@Test

View File

@ -15,10 +15,10 @@
*/
package io.netty.handler.codec;
import io.netty.buffer.BufUtil;
import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelHandlerUtil;
import io.netty.channel.ChannelInboundMessageHandler;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.channel.ChannelOutboundMessageHandler;
@ -174,10 +174,10 @@ public abstract class MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN>
protected abstract Object decode(ChannelHandlerContext ctx, INBOUND_IN msg) throws Exception;
protected void freeInboundMessage(INBOUND_IN msg) throws Exception {
ChannelHandlerUtil.freeMessage(msg);
BufUtil.free(msg);
}
protected void freeOutboundMessage(OUTBOUND_IN msg) throws Exception {
ChannelHandlerUtil.freeMessage(msg);
BufUtil.free(msg);
}
}

View File

@ -15,8 +15,8 @@
*/
package io.netty.handler.ssl;
import io.netty.buffer.BufUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFlushPromiseNotifier;
@ -779,7 +779,7 @@ public class SslHandler
if (packetLength == -1) {
// Bad data - discard the buffer and raise an exception.
NotSslRecordException e = new NotSslRecordException(
"not an SSL/TLS record: " + ByteBufUtil.hexDump(in));
"not an SSL/TLS record: " + BufUtil.hexDump(in));
in.skipBytes(in.readableBytes());
ctx.fireExceptionCaught(e);
setHandshakeFailure(e);

View File

@ -16,8 +16,8 @@
package io.netty.channel.sctp;
import com.sun.nio.sctp.MessageInfo;
import io.netty.buffer.BufUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.DefaultByteBufHolder;
/**
@ -144,6 +144,6 @@ public final class SctpMessage extends DefaultByteBufHolder {
}
return "SctpFrame{" +
"streamIdentifier=" + streamIdentifier + ", protocolIdentifier=" + protocolIdentifier +
", data=" + ByteBufUtil.hexDump(data()) + '}';
", data=" + BufUtil.hexDump(data()) + '}';
}
}

View File

@ -1,42 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.channel;
import io.netty.buffer.Freeable;
/**
* Utilities for {@link ChannelHandler} implementations.
*/
public final class ChannelHandlerUtil {
/**
* Try to free up resources that are held by the message.
*/
public static void freeMessage(Object msg) throws Exception {
if (msg instanceof Freeable) {
try {
((Freeable) msg).free();
} catch (UnsupportedOperationException e) {
// This can happen for derived buffers
// TODO: Think about this
}
}
}
private ChannelHandlerUtil() {
// Unused
}
}

View File

@ -15,6 +15,7 @@
*/
package io.netty.channel;
import io.netty.buffer.BufUtil;
import io.netty.buffer.MessageBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.TypeParameterMatcher;
@ -170,6 +171,6 @@ public abstract class ChannelInboundMessageHandlerAdapter<I>
* just pass-through the input message or need it for later usage.
*/
protected void freeInboundMessage(I msg) throws Exception {
ChannelHandlerUtil.freeMessage(msg);
BufUtil.free(msg);
}
}

View File

@ -15,6 +15,7 @@
*/
package io.netty.channel;
import io.netty.buffer.BufUtil;
import io.netty.buffer.MessageBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.TypeParameterMatcher;
@ -115,6 +116,6 @@ public abstract class ChannelOutboundMessageHandlerAdapter<I>
* just pass-through the input message or need it for later usage.
*/
protected void freeOutboundMessage(I msg) throws Exception {
ChannelHandlerUtil.freeMessage(msg);
BufUtil.free(msg);
}
}

View File

@ -15,8 +15,8 @@
*/
package io.netty.channel.socket;
import io.netty.buffer.BufUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.DefaultByteBufHolder;
import java.net.InetSocketAddress;
@ -62,6 +62,6 @@ public final class DatagramPacket extends DefaultByteBufHolder {
", data=(FREED)}";
}
return "DatagramPacket{remoteAddress=" + remoteAddress().toString() +
", data=" + ByteBufUtil.hexDump(data()) + '}';
", data=" + BufUtil.hexDump(data()) + '}';
}
}