예제 #1
0
 public int ReadBytes(byte[] value, int length)
 {
     InitializeReading();
     try
     {
         return(dataIn.Read(value, 0, length));
     }
     catch (EndOfStreamException e)
     {
         throw NMSExceptionSupport.CreateMessageEOFException(e);
     }
     catch (IOException e)
     {
         throw NMSExceptionSupport.CreateMessageFormatException(e);
     }
 }
예제 #2
0
 public double ReadDouble()
 {
     InitializeReading();
     try
     {
         return(dataIn.ReadDouble());
     }
     catch (EndOfStreamException e)
     {
         throw NMSExceptionSupport.CreateMessageEOFException(e);
     }
     catch (IOException e)
     {
         throw NMSExceptionSupport.CreateMessageFormatException(e);
     }
 }
예제 #3
0
 public string ReadString()
 {
     InitializeReading();
     try
     {
         // JMS, CMS and NMS all encode the String using a 16 bit size header.
         return(dataIn.ReadString16());
     }
     catch (EndOfStreamException e)
     {
         throw NMSExceptionSupport.CreateMessageEOFException(e);
     }
     catch (IOException e)
     {
         throw NMSExceptionSupport.CreateMessageFormatException(e);
     }
 }
예제 #4
0
        public double ReadDouble()
        {
            InitializeReading();

            try
            {
                long startingPos = this.byteBuffer.Position;
                try
                {
                    int type = this.dataIn.ReadByte();

                    switch (type)
                    {
                    case PrimitiveMap.DOUBLE_TYPE:
                        return(this.dataIn.ReadDouble());

                    case PrimitiveMap.FLOAT_TYPE:
                        return(this.dataIn.ReadSingle());

                    case PrimitiveMap.STRING_TYPE:
                        return(Single.Parse(this.dataIn.ReadString16()));

                    case PrimitiveMap.NULL:
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new NMSException("Cannot convert Null type to a double");

                    default:
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new MessageFormatException("Value is not a Double 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);
            }
        }
예제 #5
0
 public string ReadString()
 {
     InitializeReadingMode();
     try
     {
         // Note if dataIn is an EndianBinaryReader the string length is read as 16bit short
         return(dataIn.ReadString());
     }
     catch (EndOfStreamException e)
     {
         throw NMSExceptionSupport.CreateMessageEOFException(e);
     }
     catch (IOException e)
     {
         throw NMSExceptionSupport.CreateMessageFormatException(e);
     }
 }
예제 #6
0
        public byte ReadByte()
        {
            InitializeReading();

            try
            {
                long startingPos = this.byteBuffer.Position;
                try
                {
                    int type = this.dataIn.ReadByte();

                    if (type == PrimitiveMap.BYTE_TYPE)
                    {
                        return(this.dataIn.ReadByte());
                    }
                    else if (type == PrimitiveMap.STRING_TYPE)
                    {
                        return(Byte.Parse(this.dataIn.ReadString16()));
                    }
                    else if (type == PrimitiveMap.NULL)
                    {
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new NMSException("Cannot convert Null type to a byte");
                    }
                    else
                    {
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new MessageFormatException("Value is not a Byte 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);
            }
        }
예제 #7
0
        public object ReadObject()
        {
            FailIfWriteOnlyMsgBody();
            FailIfBytesInBuffer();
            object result = null;
            object value  = null;

            try
            {
                value = cloak.Peek();
                if (value == null)
                {
                    result = null;
                }
                else if (value is byte[])
                {
                    byte[] buffer = value as byte[];
                    result = new byte[buffer.Length];
                    Array.Copy(buffer, 0, result as byte[], 0, buffer.Length);
                }
                else if (ConversionSupport.IsNMSType(value))
                {
                    result = value;
                }
            }
            catch (EndOfStreamException eos)
            {
                throw NMSExceptionSupport.CreateMessageEOFException(eos);
            }
            catch (IOException ioe)
            {
                throw NMSExceptionSupport.CreateMessageFormatException(ioe);
            }
            catch (Exception e)
            {
                Tracer.InfoFormat("Unexpected exception caught reading Object stream. Exception = {0}", e);
                throw NMSExceptionSupport.Create("Unexpected exception caught reading Object stream.", e);
            }
            cloak.Pop();
            return(result);
        }
예제 #8
0
        public char ReadChar()
        {
            InitializeReading();

            try
            {
                long startingPos = this.byteBuffer.Position;
                try
                {
                    int type = this.dataIn.ReadByte();

                    switch (type)
                    {
                    case PrimitiveMap.CHAR_TYPE:
                        return(this.dataIn.ReadChar());

                    case PrimitiveMap.NULL:
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new NMSException("Cannot convert Null type to a char");

                    default:
                        this.byteBuffer.Seek(startingPos, SeekOrigin.Begin);
                        throw new MessageFormatException("Value is not a Char 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);
            }
        }
예제 #9
0
        public Object ReadObject()
        {
            InitializeReading();

            long startingPos = this.byteBuffer.Position;

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

                if (type == PrimitiveMap.BIG_STRING_TYPE)
                {
                    return(this.dataIn.ReadString32());
                }
                else if (type == PrimitiveMap.STRING_TYPE)
                {
                    return(this.dataIn.ReadString16());
                }
                else if (type == PrimitiveMap.LONG_TYPE)
                {
                    return(this.dataIn.ReadInt64());
                }
                else if (type == PrimitiveMap.INTEGER_TYPE)
                {
                    return(this.dataIn.ReadInt32());
                }
                else if (type == PrimitiveMap.SHORT_TYPE)
                {
                    return(this.dataIn.ReadInt16());
                }
                else if (type == PrimitiveMap.FLOAT_TYPE)
                {
                    return(this.dataIn.ReadSingle());
                }
                else if (type == PrimitiveMap.DOUBLE_TYPE)
                {
                    return(this.dataIn.ReadDouble());
                }
                else if (type == PrimitiveMap.CHAR_TYPE)
                {
                    return(this.dataIn.ReadChar());
                }
                else if (type == PrimitiveMap.BYTE_TYPE)
                {
                    return(this.dataIn.ReadByte());
                }
                else if (type == PrimitiveMap.BOOLEAN_TYPE)
                {
                    return(this.dataIn.ReadBoolean());
                }
                else if (type == PrimitiveMap.BYTE_ARRAY_TYPE)
                {
                    int    length = this.dataIn.ReadInt32();
                    byte[] data   = new byte[length];
                    this.dataIn.Read(data, 0, length);
                    return(data);
                }
                else if (type == PrimitiveMap.NULL)
                {
                    return(null);
                }
                else
                {
                    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);
            }
        }
예제 #10
0
        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);
            }
        }