public void TestRead()
        {
            MemoryStream baos = new MemoryStream();
            ILittleEndianOutput leo = new LittleEndianOutputStream(baos);
            leo.WriteInt(12345678);
            leo.WriteShort(12345);
            leo.WriteByte(123);
            leo.WriteShort(40000);
            leo.WriteByte(200);
            leo.WriteLong(1234567890123456789L);
            leo.WriteDouble(123.456);

            ILittleEndianInput lei = new LittleEndianInputStream(new MemoryStream(baos.ToArray()));

            Assert.AreEqual(12345678, lei.ReadInt());
            Assert.AreEqual(12345, lei.ReadShort());
            Assert.AreEqual(123, lei.ReadByte());
            Assert.AreEqual(40000, lei.ReadUShort());
            Assert.AreEqual(200, lei.ReadUByte());
            Assert.AreEqual(1234567890123456789L, lei.ReadLong());
            Assert.AreEqual(123.456, lei.ReadDouble(), 0.0);
        }
Esempio n. 2
0
        /**
   * Have the contents printer out into an OutputStream, used when writing a
   * file back out to disk (Normally, atom classes will keep their bytes
   * around, but non atom classes will just request the bytes from their
   * children, then chuck on their header and return)
   */
        public void WriteOut(Stream out1)
        {
            byte[] intbuf = new byte[LittleEndianConsts.INT_SIZE];
            byte[] shortbuf = new byte[LittleEndianConsts.SHORT_SIZE];
            byte[] zerobuf = { 0, 0, 0, 0 };
            
            LittleEndianOutputStream leosOut = new LittleEndianOutputStream(out1);

            switch (mode)
            {
                case EncodingMode.parsed:
                    {
                        MemoryStream bos = new MemoryStream();
                        LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
                        // total size, will be determined later ..

                        leos.WriteShort(Flags1);
                        leos.Write(Encoding.GetEncoding(ISO1).GetBytes(Label));
                        leos.WriteByte(0);
                        leos.Write(Encoding.GetEncoding(ISO1).GetBytes(FileName));
                        leos.WriteByte(0);
                        leos.WriteShort(Flags2);
                        leos.WriteShort(Unknown1);
                        leos.WriteInt(Command.Length + 1);
                        leos.Write(Encoding.GetEncoding(ISO1).GetBytes(Command));
                        leos.WriteByte(0);
                        leos.WriteInt(DataSize);
                        leos.Write(DataBuffer);
                        leos.WriteShort(Flags3);
                        //leos.Close(); // satisfy compiler ...

                        leosOut.WriteInt((int)bos.Length); // total size
                        bos.WriteTo(out1);
                        break;
                    }
                case EncodingMode.compact:
                    leosOut.WriteInt(DataSize + LittleEndianConsts.SHORT_SIZE);
                    leosOut.WriteShort(Flags1);
                    out1.Write(DataBuffer, 0, DataBuffer.Length);
                    break;
                default:
                case EncodingMode.unparsed:
                    leosOut.WriteInt(DataSize);
                    out1.Write(DataBuffer, 0, DataBuffer.Length);
                    break;
            }

        }