当前位置: 首页>>代码示例>>C#>>正文


C# DeflateStream.Dispose方法代码示例

本文整理汇总了C#中DeflateStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# DeflateStream.Dispose方法的具体用法?C# DeflateStream.Dispose怎么用?C# DeflateStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DeflateStream的用法示例。


在下文中一共展示了DeflateStream.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompressCanWrite

        public void CompressCanWrite()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Compress);
            Assert.True(zip.CanWrite);

            zip.Dispose();
            Assert.False(zip.CanWrite);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:DeflateStreamTests.cs

示例2: DecompressCanRead

        public void DecompressCanRead()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Decompress);

            Assert.True(zip.CanRead);

            zip.Dispose();
            Assert.False(zip.CanRead);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:DeflateStreamTests.cs

示例3: CanReadBaseStreamAfterDispose

        public async Task CanReadBaseStreamAfterDispose()
        {
            var ms = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.txt.gz"));
            var newMs = StripHeaderAndFooter.Strip(ms);

            var zip = new DeflateStream(newMs, CompressionMode.Decompress, true);
            var baseStream = zip.BaseStream;
            zip.Dispose();

            int size = 1024;
            byte[] bytes = new byte[size];
            baseStream.Read(bytes, 0, size); // This will throw if the underlying stream is not writable as expected

            baseStream.Position = 0;
            await baseStream.ReadAsync(bytes, 0, size);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:DeflateStreamTests.cs

示例4: CanDisposeDeflateStream

        public void CanDisposeDeflateStream()
        {
            var ms = new MemoryStream();
            var zip = new DeflateStream(ms, CompressionMode.Compress);
            zip.Dispose();

            // Base Stream should be null after dispose 
            Assert.Null(zip.BaseStream);

            zip.Dispose(); // Should be a no-op
        }
开发者ID:dotnet,项目名称:corefx,代码行数:11,代码来源:DeflateStreamTests.cs

示例5: FlushAsyncFailsAfterDispose

        public async Task FlushAsyncFailsAfterDispose()
        {
            var ms = new MemoryStream();
            var ds = new DeflateStream(ms, CompressionMode.Compress);
            ds.Dispose();

            await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
            {
                await ds.FlushAsync();
            });
        }
开发者ID:dotnet,项目名称:corefx,代码行数:11,代码来源:DeflateStreamTests.cs

示例6: CopyToAsyncArgumentValidation

 public void CopyToAsyncArgumentValidation()
 {
     using (DeflateStream ds = new DeflateStream(new MemoryStream(), CompressionMode.Decompress))
     {
         Assert.Throws<ArgumentNullException>("destination", () => { ds.CopyToAsync(null); });
         Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { ds.CopyToAsync(new MemoryStream(), 0); });
         Assert.Throws<NotSupportedException>(() => { ds.CopyToAsync(new MemoryStream(new byte[1], writable: false)); });
         ds.Dispose();
         Assert.Throws<ObjectDisposedException>(() => { ds.CopyToAsync(new MemoryStream()); });
     }
     using (DeflateStream ds = new DeflateStream(new MemoryStream(), CompressionMode.Compress))
     {
         Assert.Throws<NotSupportedException>(() => { ds.CopyToAsync(new MemoryStream()); });
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:DeflateStreamTests.cs

示例7: FlushFailsAfterDispose

 public void FlushFailsAfterDispose()
 {
     var ms = new MemoryStream();
     var ds = new DeflateStream(ms, CompressionMode.Compress);
     ds.Dispose();
     Assert.Throws<ObjectDisposedException>(() => { ds.Flush(); });
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:DeflateStreamTests.cs

示例8: FlushThenDispose

 public void FlushThenDispose()
 {
     var ms = new MemoryStream();
     var ds = new DeflateStream(ms, CompressionMode.Compress);
     ds.Flush();
     ds.Dispose();
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:DeflateStreamTests.cs

示例9: DoubleDispose

 public void DoubleDispose()
 {
     var ms = new MemoryStream();
     var ds = new DeflateStream(ms, CompressionMode.Compress);
     ds.Dispose();
     ds.Dispose();
 }
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:DeflateStreamTests.cs

示例10: DecompressFailsWithRealGzStream

 public async Task DecompressFailsWithRealGzStream()
 {
     string[] files = { gzTestFile("GZTestDocument.doc.gz"), gzTestFile("GZTestDocument.txt.gz") };
     foreach (string fileName in files)
     {
         var baseStream = await LocalMemoryStream.readAppFileAsync(fileName);
         var zip = new DeflateStream(baseStream, CompressionMode.Decompress);
         int _bufferSize = 2048;
         var bytes = new byte[_bufferSize];
         Assert.Throws<InvalidDataException>(() => { zip.Read(bytes, 0, _bufferSize); });
         zip.Dispose();
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:DeflateStreamTests.cs

示例11: FromXML

    public override void FromXML(XmlNode node)
    {
        if (node != null && node.Name == "layer")
        {
            XmlAttributeCollection attrs = node.Attributes;
            m_name = attrs["name"].Value;
            m_layerDimensions.first = Convert.ToInt32(attrs["width"].Value);
            m_layerDimensions.second = Convert.ToInt32(attrs["height"].Value);
            foreach(XmlNode child in node.ChildNodes)
            {
                if (child.Name == "properties")
                {
                    foreach (XmlNode propertyNode in child)
                    {
                        if (propertyNode.Name != "property")
                            continue;
                        XmlAttributeCollection propertyAtts = propertyNode.Attributes;
                        m_properties[propertyAtts["name"].Value] = propertyAtts["value"].Value;
                    }
                }
                else if (child.Name == "data")
                {
                    m_data = new TileData();
                    attrs = child.Attributes;
                    if (attrs["encoding"]!= null)
                    {
                        string[] encodings = { "", "csv", "base64" };
                        string encodingValue = attrs["encoding"].Value;
                        int encodingIdx = Array.IndexOf(encodings, encodingValue);
                        if (encodingIdx >= 0)
                        {
                            m_data.m_encoding = (TileEncodingType)encodingIdx;
                        }

                        string[] compressions = { "", "gzip", "zlib" };
                        string compression = attrs["compression"].Value;
                        int compressionIdx = Array.IndexOf(compressions, compression);
                        if (compressionIdx >= 0)
                        {
                            m_data.m_compression = (TileCompressionType)compressionIdx;
                        }

                        switch(m_data.m_encoding)
                        {
                            case TileEncodingType.kCSV:
                                {
                                    string text = child.InnerText;
                                    string[] values = text.Split(',');
                                    foreach (string v in values)
                                    {
                                        uint value = Convert.ToUInt32(v);
                                        TileInfo info = new TileInfo();
                                        info.m_horizontalFlip = (value & FLIPPED_HORIZONTALLY_FLAG) != 0;
                                        info.m_verticalFlip = (value & FLIPPED_VERTICALLY_FLAG) != 0;
                                        info.m_diagonalFlip = (value & FLIPPED_DIAGONALLY_FLAG) != 0;
                                        value = value & ~(FLIPPED_DIAGONALLY_FLAG | FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG);
                                        info.m_gid = value;
                                        m_data.m_tiles.Add(info);
                                    }
                                    break;
                                }
                            case TileEncodingType.kBase64:
                                {
                                    byte[] bytes = null;
                                    switch(m_data.m_compression)
                                    {
                                        case TileCompressionType.kNone:
                                            {
                                                bytes = Convert.FromBase64String(child.InnerText);
                                                break;
                                            }
                                        case TileCompressionType.kGzip:
                                            {
                                                //Transform string into byte[]
                                                string str = child.InnerText;
                                                byte[] byteArray = new byte[str.Length];
                                                int indexBA = 0;
                                                foreach (char item in str.ToCharArray())
                                                {
                                                    byteArray[indexBA++] = (byte)item;
                                                }

                                                MemoryStream ms = new MemoryStream(byteArray);
                                                GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress);

                                                byteArray = new byte[byteArray.Length];
                                                int rBytes = gzip.Read(byteArray, 0, byteArray.Length);

                                                StringBuilder sb = new StringBuilder(rBytes);
                                                for (int i = 0; i < rBytes; ++i)
                                                {
                                                    sb.Append((char)byteArray[i]);
                                                }

                                                gzip.Close();
                                                ms.Close();
                                                gzip.Dispose();
                                                ms.Dispose();

                                                bytes = Convert.FromBase64String(sb.ToString());
//.........这里部分代码省略.........
开发者ID:wildrabbit,项目名称:jamrabbit,代码行数:101,代码来源:TileMapLayer.cs


注:本文中的DeflateStream.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。