code: public static ChannelBuffer writeString(String msg, Charset charset) 
  	{
  		ChannelBuffer buffer = null;
  		try
  		{
  			ChannelBuffer stringBuffer = null;
  			if (null == charset)
  			{
  				charset = CharsetUtil.UTF_8;
  			}
  			stringBuffer = copiedBuffer(ByteOrder.BIG_ENDIAN, msg, charset);
  			int length = stringBuffer.readableBytes();
  			ChannelBuffer lengthBuffer = ChannelBuffers.buffer(2);
  			lengthBuffer.writeShort(length);
  			buffer = ChannelBuffers.wrappedBuffer(lengthBuffer, stringBuffer);
  		}
  		catch (Exception e)
  		{
  			throw new RuntimeException(e);
  		}
  		return buffer;
  	}
docs: Creates a channel buffer of which the first 2 bytes contain the length of
  the string in bytes and the remaining is the actual string in binary with
  specified format. Defaults to UTF-8 encoding in case charset passed in is
  null
  
  @param msg
  The string to be written.
  @param charset
  The Charset say 'UTF-8' in which the encoding needs to be
  done.
  @return The Netty channel buffer containing the string encoded as bytes
  in the provided charset. It will return <code>null</code> if the
  string parameter is null.