Apache.NMS.Util.EndianBinaryWriter.WriteString32 C# (CSharp) Метод

WriteString32() публичный Метод

Method WriteString32, writes a string to the output using the Openwire standard modified UTF-8 encoding which an int value written first to indicate the length of the encoded data, the int is read as an signed value so the max amount of data this method can write is 2^31 encoded bytes. In the case of a null value being passed this method writes a -1 to the stream to indicate that the string is null. Because modified UTF-8 encding can result in a number of bytes greater that the size of the String this method must first check that the encoding proces will not result in a value that cannot be written becuase it is greater than the max value of an int.
public WriteString32 ( String text ) : void
text String A string
Результат void
        public void WriteString32(String text)
        {
            if(text != null)
            {
                char[] charr = text.ToCharArray();
                uint utfLength = CountUtf8Bytes(charr);

                if(utfLength > int.MaxValue)
                {
                    throw new IOException(
                        String.Format(
                            "Cannot marshall an encoded string longer than: {0} bytes, supplied" +
                            "string requires: {1} characters to encode", int.MaxValue, utfLength));
                }

                byte[] bytearr = new byte[utfLength];
                encodeUTF8toBuffer(charr, bytearr);

                Write(utfLength);
                Write(bytearr);
            }
            else
            {
                Write((int) -1);
            }
        }

Usage Example

Пример #1
0
 protected void SetContent(Message message, String text)
 {
     MemoryStream mstream = new MemoryStream();
     EndianBinaryWriter dataOut = new EndianBinaryWriter(mstream);
     dataOut.WriteString32(text);
     dataOut.Close();
     message.Content = mstream.ToArray();
 }
All Usage Examples Of Apache.NMS.Util.EndianBinaryWriter::WriteString32