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

ReadObject() public method

public ReadObject ( ) : Object
return Object
        public Object ReadObject()
        {
            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();
                    case PrimitiveMap.INTEGER_TYPE:
                        return this.dataIn.ReadInt32();
                    case PrimitiveMap.SHORT_TYPE:
                        return this.dataIn.ReadInt16();
                    case PrimitiveMap.FLOAT_TYPE:
                        return this.dataIn.ReadSingle();
                    case PrimitiveMap.DOUBLE_TYPE:
                        return this.dataIn.ReadDouble();
                    case PrimitiveMap.CHAR_TYPE:
                        return this.dataIn.ReadChar();
                    case PrimitiveMap.BYTE_TYPE:
                        return this.dataIn.ReadByte();
                    case PrimitiveMap.BOOLEAN_TYPE:
                        return this.dataIn.ReadBoolean();
                    case PrimitiveMap.BYTE_ARRAY_TYPE:
                        {
                            int length = this.dataIn.ReadInt32();
                            byte[] data = new byte[length];
                            this.dataIn.Read(data, 0, length);
                            return data;
                        }
                    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 TestClearBody()
 {
     ActiveMQStreamMessage streamMessage = new ActiveMQStreamMessage();
     try
     {
         streamMessage.WriteObject((Int64) 2);
         streamMessage.ClearBody();
         Assert.IsFalse(streamMessage.ReadOnlyBody);
         streamMessage.WriteObject((Int64) 2);
         streamMessage.ReadObject();
         Assert.Fail("should throw exception");
     }
     catch(MessageNotReadableException)
     {
     }
     catch(MessageNotWriteableException)
     {
         Assert.Fail("should be writeable");
     }
 }
All Usage Examples Of Apache.NMS.ActiveMQ.Commands.ActiveMQStreamMessage::ReadObject