Apache.NMS.ActiveMQ.Commands.ActiveMQStreamMessage.ReadString C# (CSharp) Method

ReadString() public method

public ReadString ( ) : string
return string
        public string ReadString()
        {
            InitializeReading();

            long startingPos = this.byteBuffer.Position;

            try
            {
                int type = this.dataIn.ReadByte();

                switch (type)
                {
                    case PrimitiveMap.BIG_STRING_TYPE:
                        return this.dataIn.ReadString32();
                    case PrimitiveMap.STRING_TYPE:
                        return this.dataIn.ReadString16();
                    case PrimitiveMap.LONG_TYPE:
                        return this.dataIn.ReadInt64().ToString();
                    case PrimitiveMap.INTEGER_TYPE:
                        return this.dataIn.ReadInt32().ToString();
                    case PrimitiveMap.SHORT_TYPE:
                        return this.dataIn.ReadInt16().ToString();
                    case PrimitiveMap.FLOAT_TYPE:
                        return this.dataIn.ReadSingle().ToString();
                    case PrimitiveMap.DOUBLE_TYPE:
                        return this.dataIn.ReadDouble().ToString();
                    case PrimitiveMap.CHAR_TYPE:
                        return this.dataIn.ReadChar().ToString();
                    case PrimitiveMap.BYTE_TYPE:
                        return this.dataIn.ReadByte().ToString();
                    case PrimitiveMap.BOOLEAN_TYPE:
                        return this.dataIn.ReadBoolean().ToString();
                    case PrimitiveMap.NULL:
                        return null;
                    default:
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new MessageFormatException("Value is not a known type.");
                }
            }
            catch(FormatException e)
            {
                this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                throw NMSExceptionSupport.CreateMessageFormatException(e);
            }
            catch(EndOfStreamException e)
            {
                throw NMSExceptionSupport.CreateMessageEOFException(e);
            }
            catch(IOException e)
            {
                throw NMSExceptionSupport.CreateMessageFormatException(e);
            }
        }

Usage Example

        public void TestReadBigString()
        {
            ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
            // Test with a 1Meg String
            StringBuilder bigSB = new StringBuilder(1024 * 1024);
            for(int i = 0; i < 1024 * 1024; i++)
            {
                bigSB.Append((char)'a' + i % 26);
            }
            String bigString = bigSB.ToString();

            msg.WriteString(bigString);
            msg.Reset();
            Assert.AreEqual(bigString, msg.ReadString());
        }
All Usage Examples Of Apache.NMS.ActiveMQ.Commands.ActiveMQStreamMessage::ReadString