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


C# Stream.Close方法代码示例

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


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

示例1: WriteXFormToXmlFile

        /// <summary>
        /// Write data from form to output stream.
        /// </summary>
        /// <param name="stream">Output stream.</param>
        /// <param name="xForm">XForm with data.</param>
        public void WriteXFormToXmlFile(Stream stream, XForm xForm)
        {
            var settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;

            using (var writer = System.Xml.XmlWriter.Create(stream, settings))
            {
                writer.WriteStartElement(xForm.Root.Name);
                writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");

                foreach (var xAttribute in xForm.Root.Attributes)
                {
                    writer.WriteAttributeString(xAttribute.Name, xAttribute.GetStringXmlValue());
                }

                foreach (var xElement in xForm.Root.Elements)
                {
                    xElement.WriteXml(writer);
                }

                foreach (var xContainer in xForm.Root.Containers)
                {
                    xContainer.WriteXml(writer);
                }

                writer.WriteEndElement();
            }

            stream.Close();
        }
开发者ID:janstafa,项目名称:XsdFormEditor,代码行数:36,代码来源:XmlWriter.cs

示例2: Get

 public static string Get(Stream fs)
 {
     HashAlgorithm ha = HashAlgorithm.Create();
     byte[] bytes = ha.ComputeHash(fs);
     fs.Close();
     return ToHexString(bytes);
 }
开发者ID:tangzx,项目名称:ABSystem,代码行数:7,代码来源:HashUtil.cs

示例3: Art

 public Art(Stream input)
 {
     ImageData=new byte[input.Length];
     input.Read(ImageData, 0, ImageData.Length);
     input.Close();
     input.Dispose();
 }
开发者ID:killwort,项目名称:musicdata,代码行数:7,代码来源:Art.cs

示例4: load

        /// <summary>
        ///     Reads a generic Pokémon container from a Stream.
        ///     Those containers are the ones that starts with "GR", "MM", "AD" and so on...
        /// </summary>
        /// <param name="data">Stream with container data</param>
        /// <returns></returns>
        public static OContainer load(Stream data)
        {
            BinaryReader input = new BinaryReader(data);
            OContainer output = new OContainer();

            IOUtils.readString(input, 0, 2); //Magic
            ushort sectionCount = input.ReadUInt16();
            for (int i = 0; i < sectionCount; i++)
            {
                OContainer.fileEntry entry = new OContainer.fileEntry();

                data.Seek(4 + (i * 4), SeekOrigin.Begin);
                uint startOffset = input.ReadUInt32();
                uint endOffset = input.ReadUInt32();
                uint length = endOffset - startOffset;

                data.Seek(startOffset, SeekOrigin.Begin);
                byte[] buffer = new byte[length];
                input.Read(buffer, 0, (int)length);
                entry.data = buffer;

                output.content.Add(entry);
            }

            data.Close();

            return output;
        }
开发者ID:CryogenicTyrant,项目名称:Ohana3DS-Rebirth,代码行数:34,代码来源:PkmnContainer.cs

示例5: RenderFromExcel

        public static DataTable RenderFromExcel(Stream ExcelFileStream, string SheetName, int HeaderRowIndex)
        {
            var workbook = new HSSFWorkbook(ExcelFileStream);
            var sheet = workbook.GetSheet(SheetName);

            var table = new DataTable();

            var headerRow = sheet.GetRow(HeaderRowIndex);
            int cellCount = headerRow.LastCellNum;

            for (int i = headerRow.FirstCellNum; i < cellCount; i++)
            {
                var column = new DataColumn(headerRow.GetCell(i).StringCellValue);
                table.Columns.Add(column);
            }

            int rowCount = sheet.LastRowNum;

            for (int i = (sheet.FirstRowNum + 1); i < sheet.LastRowNum; i++)
            {
                var row = sheet.GetRow(i);
                var dataRow = table.NewRow();

                for (int j = row.FirstCellNum; j < cellCount; j++)
                    dataRow[j] = row.GetCell(j).ToString();
            }

            ExcelFileStream.Close();
            workbook = null;
            sheet = null;
            return table;
        }
开发者ID:weiliji,项目名称:MyFramework,代码行数:32,代码来源:ExcelUtils.cs

示例6: CloseStream

 public void CloseStream(Stream stream)
 {
     if (stream != null)
     {
         stream.Close();
     }
 }
开发者ID:Sirais,项目名称:taglib-sharp-portable,代码行数:7,代码来源:LocalFileAbstraction.cs

示例7: OpenAndAddToWordprocessingStream

 private static void OpenAndAddToWordprocessingStream(Stream stream, string txt)
 {
     Document doc = new Document(stream);
     stream.Close();
     DocumentBuilder db = new DocumentBuilder(doc);
     db.Writeln(txt);
     doc.Save(FileName);
 }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:8,代码来源:Program.cs

示例8: ReadToEnd

 public byte[] ReadToEnd(string path)
 {
     Stream = new FileStream(path, FileMode.Open);
     var memoryStream = new MemoryStream();
     Stream.CopyTo(memoryStream);
     Stream.Close();
     return memoryStream.ToArray();
 }
开发者ID:QTruffart,项目名称:MonkeyMusicCloud,代码行数:8,代码来源:StreamHelper.cs

示例9: Check

 public bool Check(Stream stream, bool closeStream = false)
 {
     var buffer = new byte[5];
     stream.Read(buffer, 0, 5);
     if (closeStream)
         stream.Close();
     return Check(buffer, 5);
 }
开发者ID:JonasSyrstad,项目名称:Stardust,代码行数:8,代码来源:Utf7Checker.cs

示例10: load

        /// <summary>
        ///     Reads a DARC archive.
        /// </summary>
        /// <param name="data">Stream of the data</param>
        /// <returns>The container data</returns>
        public static OContainer load(Stream data)
        {
            OContainer output = new OContainer();
            BinaryReader input = new BinaryReader(data);

            string darcMagic = IOUtils.readStringWithLength(input, 4);
            ushort endian = input.ReadUInt16();
            ushort headerLength = input.ReadUInt16();
            uint version = input.ReadUInt32();
            uint fileSize = input.ReadUInt32();
            uint tableOffset = input.ReadUInt32();
            uint tableLength = input.ReadUInt32();
            uint dataOffset = input.ReadUInt32();

            data.Seek(tableOffset, SeekOrigin.Begin);
            fileEntry root = getEntry(input);
            int baseOffset = (int)data.Position;
            int namesOffset = (int)(tableOffset + root.length * 0xc);

            string currDir = null;
            for (int i = 0; i < root.length - 1; i++)
            {
                data.Seek(baseOffset + i * 0xc, SeekOrigin.Begin);

                fileEntry entry = getEntry(input);

                if ((entry.flags & 1) > 0)
                {
                    //Folder
                    int index = i;
                    currDir = null;
                    for (;;)
                    {
                        uint parentIndex = entry.offset;
                        currDir = getName(input, entry.nameOffset + namesOffset) + "/" + currDir;
                        if (parentIndex == 0 || parentIndex == index) break;
                        data.Seek(baseOffset + parentIndex * 0xc, SeekOrigin.Begin);
                        entry = getEntry(input);
                        index = (int)parentIndex;
                    }

                    continue;
                }

                data.Seek(entry.offset, SeekOrigin.Begin);
                byte[] buffer = new byte[entry.length];
                data.Read(buffer, 0, buffer.Length);

                OContainer.fileEntry file = new OContainer.fileEntry();
                file.name = currDir + getName(input, entry.nameOffset + namesOffset);
                file.data = buffer;

                output.content.Add(file);
            }

            data.Close();
            return output;
        }
开发者ID:Quibilia,项目名称:Ohana3DS-Transfigured,代码行数:63,代码来源:DARC.cs

示例11: SubirFichero

 public void SubirFichero(Stream fichero, string nombre, string contenedor = null)
 {
     ComprobarContenedor();
     var cliente = _cuenta.CreateCloudBlobClient();
     var cont = cliente.GetContainerReference(_contenedor);
     var blob = cont.GetBlockBlobReference(nombre);
     blob.UploadFromStream(fichero);
     fichero.Close();
 }
开发者ID:FranLsz,项目名称:SubidaFicherosMVC,代码行数:9,代码来源:AzureStorageUtil.cs

示例12: CleanTo

 public void CleanTo(Stream strDest)
 {
     using (DocxDocumentProcessor dp = new DocxDocumentProcessor(m_data.AsStream()))
     {
         dp.Output = strDest;
         dp.Process(DocumentProcessingActions.Clean);
         strDest.Close();
     }
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:9,代码来源:DocxDocumentReader.cs

示例13: CorrectView

        private Stream CorrectView(string virtualPath, Stream stream)
        {
            if (_viewFixer == null)
                return stream;

            var outStream = _viewFixer.CorrectView(virtualPath, stream);
            stream.Close();
            return outStream;
        }
开发者ID:rvukovic,项目名称:griffin.mvccontrib,代码行数:9,代码来源:EmbeddedViewFileProvider.cs

示例14: SubirFichero

        public void SubirFichero(Stream fichero, string nombre, string contenedor = null)
        {
            ComprobarContenedor(contenedor);

            var cliente = _cuenta.CreateCloudBlobClient();
            var cont = cliente.GetContainerReference(_contenedor);
            var blob = cont.GetBlockBlobReference(nombre);
            blob.UploadFromStream(fichero); //podría hacerse upload de array binario, texto, etc
            fichero.Close();
        }
开发者ID:AlvaroDama,项目名称:ContactosWebAPI,代码行数:10,代码来源:AzureStorageUtils.cs

示例15: load

        /// <summary>
        ///     Loads a Fantasy Life ZTEX texture from a Stream.
        /// </summary>
        /// <param name="data">The Stream with the data</param>
        /// <returns>The list of textures</returns>
        public static List<RenderBase.OTexture> load(Stream data)
        {
            List<RenderBase.OTexture> textures = new List<RenderBase.OTexture>();

            BinaryReader input = new BinaryReader(data);

            string ztexMagic = IOUtils.readString(input, 0, 4);
            ushort textureCount = input.ReadUInt16();
            input.ReadUInt16();
            input.ReadUInt32();

            List<textureEntry> entries = new List<textureEntry>();
            for (int i = 0; i < textureCount; i++)
            {
                textureEntry entry = new textureEntry();

                entry.name = IOUtils.readString(input, (uint)(0xc + (i * 0x58)));
                data.Seek(0xc + (i * 0x58) + 0x40, SeekOrigin.Begin);

                input.ReadUInt32();
                entry.offset = input.ReadUInt32();
                input.ReadUInt32();
                entry.length = input.ReadUInt32();
                entry.width = input.ReadUInt16();
                entry.height = input.ReadUInt16();
                input.ReadByte();
                entry.format = input.ReadByte();
                input.ReadUInt16();

                entries.Add(entry);
            }

            foreach (textureEntry entry in entries)
            {
                data.Seek(entry.offset, SeekOrigin.Begin);
                byte[] buffer = new byte[entry.length];
                data.Read(buffer, 0, buffer.Length);

                Bitmap bmp = null;
                switch (entry.format)
                {
                    case 1: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.rgb565); break;
                    case 5: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.rgba4); break;
                    case 9: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.rgba8); break;
                    case 0x18: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.etc1); break;
                    case 0x19: bmp = TextureCodec.decode(buffer, entry.width, entry.height, RenderBase.OTextureFormat.etc1a4); break;
                }

                textures.Add(new RenderBase.OTexture(bmp, entry.name));
            }

            data.Close();

            return textures;
        }
开发者ID:Quibilia,项目名称:Ohana3DS-Transfigured,代码行数:60,代码来源:ZTEX.cs


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