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


C# GZipStream.Dispose方法代码示例

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


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

示例1: CanDisposeGZipStream

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

            Assert.Null(zip.BaseStream);

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

示例2: CompressCanWrite

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

            zip.Dispose();
            Assert.False(zip.CanWrite, "GZipStream CanWrite after dispose");
        }
开发者ID:Cythical,项目名称:corefx,代码行数:9,代码来源:GZipStreamTests.cs

示例3: DecompressCanRead

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

            Assert.True(zip.CanRead, "GZipStream not CanRead in Decompress");

            zip.Dispose();
            Assert.False(zip.CanRead, "GZipStream CanRead after dispose in Decompress");
        }
开发者ID:Cythical,项目名称:corefx,代码行数:10,代码来源:GZipStreamTests.cs

示例4: CompressFile

    public static void CompressFile(string toCompressFileName,string targetFileName,bool IsDeleteSourceFile)
    {
        FileStream reader;
        reader = File.Open(toCompressFileName, FileMode.Open);
        FileStream writer;
        writer = File.Create(targetFileName);
       
        //压缩相关的流
        MemoryStream ms = new MemoryStream();
        GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress, true);


        //往压缩流中写数据
        byte[] sourceBuffer = new byte[reader.Length];
        reader.Read(sourceBuffer, 0, sourceBuffer.Length);
        zipStream.Write(sourceBuffer, 0, sourceBuffer.Length);
       
        //一定要在内存流读取之前关闭压缩流
        zipStream.Close();
        zipStream.Dispose();
       
        //从内存流中读数据
        ms.Position = 0; //注意,不要遗漏此句
        byte[] destBuffer = new byte[ms.Length];
        ms.Read(destBuffer, 0, destBuffer.Length);
        writer.Write(destBuffer, 0, destBuffer.Length);
       
        //关闭并释放内存流
        ms.Close();
        ms.Dispose();
       
        //关闭并释放文件流
        writer.Close();
        writer.Dispose();
        reader.Close();
        reader.Dispose();
        if (IsDeleteSourceFile)
        {
            File.Delete(toCompressFileName);
        }
    }
开发者ID:lakeli,项目名称:shizong,代码行数:41,代码来源:RarHelper.cs

示例5: 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

示例6: TestSeekMethodsCompress

        public void TestSeekMethodsCompress()
        {
            var ms = new MemoryStream();
            var zip = new GZipStream(ms, CompressionMode.Compress);

            Assert.False(zip.CanSeek);

            Assert.Throws<NotSupportedException>(delegate { long value = zip.Length; });
            Assert.Throws<NotSupportedException>(delegate { long value = zip.Position; });
            Assert.Throws<NotSupportedException>(delegate { zip.Position = 100L; });
            Assert.Throws<NotSupportedException>(delegate { zip.SetLength(100L); });
            Assert.Throws<NotSupportedException>(delegate { zip.Seek(100L, SeekOrigin.Begin); });

            zip.Dispose();
            Assert.False(zip.CanSeek);
        }
开发者ID:Cythical,项目名称:corefx,代码行数:16,代码来源:GZipStreamTests.cs

示例7: FlushAsyncFailsAfterDispose

 public async Task FlushAsyncFailsAfterDispose()
 {
     var ms = new MemoryStream();
     var ds = new GZipStream(ms, CompressionMode.Compress);
     ds.Dispose();
     await Assert.ThrowsAsync<ObjectDisposedException>(async () =>
     {
         await ds.FlushAsync();
     });
 }
开发者ID:Cythical,项目名称:corefx,代码行数:10,代码来源:GZipStreamTests.cs

示例8: FlushFailsAfterDispose

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

示例9: CanReadBaseStreamAfterDispose

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

            var zip = new GZipStream(ms, 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 writeable as expected
        }
开发者ID:Cythical,项目名称:corefx,代码行数:12,代码来源:GZipStreamTests.cs

示例10: CopyToAsyncArgumentValidation

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

示例11: DecompressFile

    public static void DecompressFile(string toDecompressFileName, string targetFileName, bool IsDeleteSourceFile)
    {
        //文件流
        FileStream reader;
        reader = File.Open(toDecompressFileName, FileMode.Open);
        FileStream writer;
        writer = File.Create(targetFileName);

        //解压相关的流,同时向内存流中写数据
        byte[] sourceBuffer = new byte[reader.Length];
        reader.Read(sourceBuffer, 0, sourceBuffer.Length);
        MemoryStream ms = new MemoryStream(sourceBuffer);
        GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress, true);

        byte[] destBuffer = new byte[1];
        while (zipStream.Read(destBuffer, 0, destBuffer.Length) > 0)
        {
            writer.Write(destBuffer, 0, destBuffer.Length);
        }

        //释放并关闭解压流和内存流
        zipStream.Close();
        zipStream.Dispose();
        ms.Close();
        ms.Dispose();

        //关闭并释放文件流
        writer.Close();
        writer.Dispose();
        reader.Close();
        reader.Dispose();
        if (IsDeleteSourceFile)
        {
            File.Delete(toDecompressFileName);
        }
    }
开发者ID:lakeli,项目名称:shizong,代码行数:36,代码来源:RarHelper.cs


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