diff --git a/src/main/java/org/jboss/netty/buffer/ChannelBuffers.java b/src/main/java/org/jboss/netty/buffer/ChannelBuffers.java index 2b6a6a87a5..9b17366654 100644 --- a/src/main/java/org/jboss/netty/buffer/ChannelBuffers.java +++ b/src/main/java/org/jboss/netty/buffer/ChannelBuffers.java @@ -60,20 +60,20 @@ import java.nio.charset.UnsupportedCharsetException; *

Creating a wrapped buffer

* * Wrapped buffer is a buffer which is a view of one or more existing - * byte arrays, byte buffer and string. Any changes in the content of the - * original array or buffer will be reflected in the wrapped buffer. Various - * wrapper methods are provided and their name is all {@code wrappedBuffer()}. + * byte arrays and byte buffers. Any changes in the content of the original + * array or buffer will be reflected in the wrapped buffer. Various wrapper + * methods are provided and their name is all {@code wrappedBuffer()}. * You might want to take a look at this method closely if you want to create * a buffer which is composed of more than one array to reduce the number of * memory copy. * *

Creating a copied buffer

* - * Copied buffer is a deep copy of one or more existing byte arrays or byte - * buffer. Unlike a wrapped buffer, there's no shared data between the - * original arrays and the copied buffer. Various copy methods are provided - * and their name is all {@code copiedBuffer()}. It's also convenient to - * use this operation to merge multiple buffers into one buffer. + * Copied buffer is a deep copy of one or more existing byte arrays, byte + * buffers or a string. Unlike a wrapped buffer, there's no shared data + * between the original data and the copied buffer. Various copy methods are + * provided and their name is all {@code copiedBuffer()}. It's also convenient + * to use this operation to merge multiple buffers into one buffer. * *

Miscellaneous utility methods

* @@ -347,14 +347,6 @@ public class ChannelBuffers { return wrappedBuffer(wrappedBuffers); } - public static ChannelBuffer wrappedBuffer(String string, String charsetName) { - try { - return wrappedBuffer(string.getBytes(charsetName)); - } catch (UnsupportedEncodingException e) { - throw new UnsupportedCharsetException(charsetName); - } - } - public static ChannelBuffer copiedBuffer(byte[] array) { return copiedBuffer(BIG_ENDIAN, array); } @@ -466,6 +458,14 @@ public class ChannelBuffers { return wrappedBuffer(copiedBuffers); } + public static ChannelBuffer copiedBuffer(String string, String charsetName) { + try { + return wrappedBuffer(string.getBytes(charsetName)); + } catch (UnsupportedEncodingException e) { + throw new UnsupportedCharsetException(charsetName); + } + } + public static ChannelBuffer unmodifiableBuffer(ChannelBuffer buffer) { if (buffer instanceof ReadOnlyChannelBuffer) { buffer = ((ReadOnlyChannelBuffer) buffer).unwrap(); diff --git a/src/main/java/org/jboss/netty/handler/codec/string/StringEncoder.java b/src/main/java/org/jboss/netty/handler/codec/string/StringEncoder.java index f54bd351a1..e5420b73af 100644 --- a/src/main/java/org/jboss/netty/handler/codec/string/StringEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/string/StringEncoder.java @@ -74,6 +74,6 @@ public class StringEncoder implements ChannelDownstreamHandler { } write(context, e.getChannel(), e.getFuture(), - wrappedBuffer(String.valueOf(e.getMessage()), charsetName)); + copiedBuffer(String.valueOf(e.getMessage()), charsetName)); } }