コード例 #1
0
ファイル: ByteArray.cs プロジェクト: melongroup/U3DExport
 public void Compress(string algorithm)
 {
     if (algorithm == CompressionAlgorithm.Deflate)
     {
         byte[]        buffer        = _memoryStream.ToArray();
         MemoryStream  ms            = new MemoryStream();
         DeflateStream deflateStream = new DeflateStream(ms, CompressionMode.Compress, true);
         deflateStream.Write(buffer, 0, buffer.Length);
         deflateStream.Close();
         _memoryStream.Close();
         _memoryStream = ms;
         AMFReader amfReader = new AMFReader(_memoryStream);
         AMFWriter amfWriter = new AMFWriter(_memoryStream);
         _dataOutput = new DataOutput(amfWriter);
         _dataInput  = new DataInput(amfReader);
     }
     if (algorithm == CompressionAlgorithm.Zlib)
     {
         byte[]       buffer     = _memoryStream.ToArray();
         MemoryStream ms         = new MemoryStream();
         ZlibStream   zlibStream = new ZlibStream(ms, CompressionMode.Compress, true);
         zlibStream.Write(buffer, 0, buffer.Length);
         zlibStream.Flush();
         zlibStream.Close();
         zlibStream.Dispose();
         _memoryStream.Close();
         _memoryStream = ms;
         AMFReader amfReader = new AMFReader(_memoryStream);
         AMFWriter amfWriter = new AMFWriter(_memoryStream);
         _dataOutput = new DataOutput(amfWriter);
         _dataInput  = new DataInput(amfReader);
     }
 }
コード例 #2
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase collection = data as NameObjectCollectionBase;

            object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null && attributes.Length > 0)
            {
                DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                PropertyInfo           pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
                if (pi != null)
                {
                    ASObject aso = new ASObject();

                    IEnumerator enumList = collection.Keys.GetEnumerator();

                    //为了兼容 webplayer 和手机 platform 而改掉的代码,原来的代码见后面的注释内容.
                    while (enumList.MoveNext())
                    {
                        string key   = enumList.Current as string;
                        object value = pi.GetValue(collection, new object[] { key });

                        aso.Add(key, value);
                    }
                    writer.WriteByte(AMF3TypeCode.Object);
                    writer.WriteAMF3Object(aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
コード例 #3
0
ファイル: ByteArray.cs プロジェクト: melongroup/U3DExport
        public void Uncompress(string algorithm)
        {
            if (algorithm == CompressionAlgorithm.Zlib)
            {
                Position = 0;
                ZlibStream   deflateStream = new ZlibStream(_memoryStream, CompressionMode.Decompress, false);
                MemoryStream ms            = new MemoryStream();
                byte[]       buffer        = new byte[1024];
                // Chop off the first two bytes
                //int b = _memoryStream.ReadByte();
                //b = _memoryStream.ReadByte();
                while (true)
                {
                    int readCount = deflateStream.Read(buffer, 0, buffer.Length);
                    if (readCount > 0)
                    {
                        ms.Write(buffer, 0, readCount);
                    }
                    else
                    {
                        break;
                    }
                }
                deflateStream.Close();
                _memoryStream.Close();
                _memoryStream.Dispose();
                _memoryStream          = ms;
                _memoryStream.Position = 0;
            }
            if (algorithm == CompressionAlgorithm.Deflate)
            {
                Position = 0;
                DeflateStream deflateStream = new DeflateStream(_memoryStream, CompressionMode.Decompress, false);
                MemoryStream  ms            = new MemoryStream();
                byte[]        buffer        = new byte[1024];
                while (true)
                {
                    int readCount = deflateStream.Read(buffer, 0, buffer.Length);
                    if (readCount > 0)
                    {
                        ms.Write(buffer, 0, readCount);
                    }
                    else
                    {
                        break;
                    }
                }
                deflateStream.Close();
                _memoryStream.Close();
                _memoryStream.Dispose();
                _memoryStream          = ms;
                _memoryStream.Position = 0;
            }
            AMFReader amfReader = new AMFReader(_memoryStream);
            AMFWriter amfWriter = new AMFWriter(_memoryStream);

            _dataOutput = new DataOutput(amfWriter);
            _dataInput  = new DataInput(amfReader);
        }
コード例 #4
0
        public void WriteData(AMFWriter writer, object data)
        {
            IList list = data as IList;

            if (list != null)
            {
                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(list);
                return;
            }

            IListSource listSource = data as IListSource;

            if (listSource != null)
            {
                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(listSource.GetList());
                return;
            }

            IDictionary dictionary = data as IDictionary;

            if (dictionary != null)
            {
                writer.WriteByte(AMF3TypeCode.Dictionary);
                writer.WriteAMF3Dictionary(dictionary);
                return;
            }
            if (data is Exception)
            {
                writer.WriteByte(AMF3TypeCode.Object);
                writer.WriteAMF3Object(data);
                return;
            }
            if (data is IExternalizable)
            {
                writer.WriteByte(AMF3TypeCode.Object);
                writer.WriteAMF3Object(data);
                return;
            }
            if (data is IEnumerable)
            {
                ArrayList tmp = new ArrayList();
                foreach (object element in (data as IEnumerable))
                {
                    tmp.Add(element);
                }

                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(tmp);

                return;
            }
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
コード例 #5
0
ファイル: ByteArray.cs プロジェクト: melongroup/U3DExport
        public ByteArray(MemoryStream ms)
        {
            _memoryStream = ms;
            AMFReader amfReader = new AMFReader(_memoryStream);
            AMFWriter amfWriter = new AMFWriter(_memoryStream);

            _dataOutput     = new DataOutput(amfWriter);
            _dataInput      = new DataInput(amfReader);
            _objectEncoding = ObjectEncoding.AMF3;
        }
コード例 #6
0
        public void WriteData(AMFWriter writer, object data)
        {
            IList list = data as IList;

            if (list != null)
            {
                writer.WriteByte(AMF3TypeCode.ObjectVector);
                writer.WriteAMF3ObjectVector(list);
            }
        }
コード例 #7
0
ファイル: ByteArray.cs プロジェクト: melongroup/U3DExport
        public ByteArray(byte[] buffer)
        {
            _memoryStream = new MemoryStream();
            _memoryStream.Write(buffer, 0, buffer.Length);
            _memoryStream.Position = 0;
            AMFReader amfReader = new AMFReader(_memoryStream);
            AMFWriter amfWriter = new AMFWriter(_memoryStream);

            _dataOutput     = new DataOutput(amfWriter);
            _dataInput      = new DataInput(amfReader);
            _objectEncoding = ObjectEncoding.AMF3;
        }
コード例 #8
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteByte(AMF3TypeCode.ObjectVector);
     writer.WriteAMF3ObjectVector(data as IList);
 }
コード例 #9
0
        public void WriteData(AMFWriter writer, object data)
        {
            int value = Convert.ToInt32(data);

            writer.WriteAMF3Int(value);
        }
コード例 #10
0
        public void WriteData(AMFWriter writer, object data)
        {
            double value = Convert.ToDouble(data);

            writer.WriteAMF3Double(value);
        }
コード例 #11
0
        public void WriteData(AMFWriter writer, object data)
        {
            Type type = data.GetType().GetElementType();

            if (type == typeof(object))
            {
                writer.WriteByte(AMF3TypeCode.Array);
                writer.WriteAMF3Array(data as Array);
                return;
            }

            if (type == typeof(int))
            {
                writer.WriteByte(AMF3TypeCode.IntVector);

                IList      rawData = (IList)data;
                List <int> list    = new List <int>(rawData.Count);
                foreach (int item in rawData)
                {
                    list.Add(item);
                }

                writer.WriteAMF3IntVector(list, data is Array);
                return;
            }

            if (type == typeof(uint))
            {
                writer.WriteByte(AMF3TypeCode.UIntVector);

                IList       rawData = (IList)data;
                List <uint> list    = new List <uint>(rawData.Count);
                foreach (uint item in rawData)
                {
                    list.Add(item);
                }
                writer.WriteAMF3UIntVector(list, data is Array);
                return;
            }

            if (type == typeof(float))
            {
                writer.WriteByte(AMF3TypeCode.NumberVector);
                IList         rawData = (IList)data;
                List <double> list    = new List <double>(rawData.Count);
                foreach (float item in rawData)
                {
                    list.Add(Convert.ToDouble(item));
                }
                writer.WriteAMF3DoubleVector(list, data is Array);
                return;
            }

            if (type == typeof(double))
            {
                writer.WriteByte(AMF3TypeCode.NumberVector);
                IList         rawData = (IList)data;
                List <double> list    = new List <double>(rawData.Count);
                foreach (double item in rawData)
                {
                    list.Add(item);
                }
                writer.WriteAMF3DoubleVector(list, data is Array);
                return;
            }


            writer.WriteByte(AMF3TypeCode.ObjectVector);
            writer.WriteAMF3ObjectVector(data as IList);
        }
コード例 #12
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteAMF3XmlDocument(data as XmlDocument);
 }
コード例 #13
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteByte(AMF3TypeCode.DateTime);
     writer.WriteAMF3DateTime((DateTime)data);
 }
コード例 #14
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteAMF3String(((Guid)data).ToString());
 }
コード例 #15
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteAMF3String(new String((char)data, 1));
 }