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


C# BinaryReader.Close方法代码示例

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


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

示例1: fromFile

        public Boolean fromFile(String path)
        {
            FileStream fs = new FileStream(path, FileMode.Open);
            BinaryReader reader = new BinaryReader(fs);
            try
            {
                String h = reader.ReadString();
                float v = BitConverter.ToSingle(reader.ReadBytes(sizeof(float)), 0);
                drawFloorModel = reader.ReadBoolean();
                showAlwaysFloorMap = reader.ReadBoolean();
                lockMapSize = reader.ReadBoolean();
                mapXsize = reader.ReadInt32();
                mapYsize = reader.ReadInt32();

                //edgeXのxはmapX-1
                //yはmapYsize

                return true;

            }
            catch (EndOfStreamException eex)
            {
                //握りつぶす
                return false;
            }
            finally
            {
                reader.Close();
            }
        }
开发者ID:kistvan,项目名称:geditor,代码行数:30,代码来源:EditorConfig.cs

示例2: DeCrypting

 private static string DeCrypting()
 {
     var res = string.Empty;
     var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan);
     var reader = new BinaryReader(file);
     var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write,
         FileShare.None, 32, FileOptions.WriteThrough));
     try
     {
         var pos = 0;
         while (pos < file.Length)
         {
             var c = reader.ReadUInt16();
             //var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR());
             var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR());
             if (pos < 256) res += pow + " ";
             writer.Write((byte)(pow));
             pos += 2;
         }
     }
     finally
     {
         writer.Close();
         reader.Close();
     }
     return "Decoding Complete!\n" + res;
 }
开发者ID:Emaxan,项目名称:TI_Laba4_RSA,代码行数:27,代码来源:Decoding.cs

示例3: GetPEType

        public static PEType GetPEType(string path)
        {
            if (string.IsNullOrEmpty(path))
                return PEType.Unknown;

            var br =
                new BinaryReader(new FileStream(path,
                                                FileMode.Open,
                                                FileAccess.Read,
                                                FileShare.ReadWrite
                                     ));

            br.BaseStream.Seek(0x3C, SeekOrigin.Begin);
            br.BaseStream.Seek(br.ReadInt32() + 4, SeekOrigin.Begin);
            ushort machine = br.ReadUInt16();

            br.Close();

            if (machine == 0x014C)
                return PEType.X32;

            if (machine == 0x8664)
                return PEType.X64;

            return PEType.Unknown;
        }
开发者ID:qwehkkk,项目名称:Locale-Emulator,代码行数:26,代码来源:PEFileReader.cs

示例4: Process

        public static ExtractedM2 Process(string basePath, MapId mapId, string path)
        {
            basePath = Path.Combine(basePath, mapId.ToString());
            var filePath = Path.Combine(basePath, path);
            filePath = Path.ChangeExtension(filePath, ".m2x");

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Extracted M2 file not found: {0}", filePath);
            }

            var m2 = new ExtractedM2();

            using(var file = File.OpenRead(filePath))
            using(var br = new BinaryReader(file))
            {
                var type = br.ReadString();
                if (type != fileType)
                {
                    br.Close();
                    throw new InvalidDataException(string.Format("M2x file in invalid format: {0}", filePath));
                }

                m2.Extents = br.ReadBoundingBox();
                m2.BoundingVertices = br.ReadVector3List();
                m2.BoundingTriangles = br.ReadIndex3List();

                br.Close();
            }

            return m2;
        }
开发者ID:WCell,项目名称:WCell-Terrain,代码行数:32,代码来源:ExtractedM2Parser.cs

示例5: Load

 public static MacroBook[] Load(Character C)
 {
     string BookNameFile = C.GetUserFileName("mcr.ttl");
       if (!File.Exists(BookNameFile))
     return null;
     BinaryReader BR = new BinaryReader(new FileStream(BookNameFile, FileMode.Open, FileAccess.Read), Encoding.ASCII);
     int BookCount = 1;
       if ((BR.BaseStream.Length - 0x18) % 16 != 0 || BR.ReadUInt32() != 1) {
     BR.Close();
     return null;
       }
       else {
     BookCount = (int) ((BR.BaseStream.Length - 0x18) / 16);
       }
       BR.BaseStream.Seek(0x18, SeekOrigin.Begin);
     List<MacroBook> Books = new List<MacroBook>();
       for (int i = 0; i < BookCount; ++i) {
       MacroBook MB = new MacroBook(BookNameFile, i, new string(BR.ReadChars(16)).TrimEnd('\0'));
     for (int j = 0; j < 10; ++j)
       MB.Folders.Add(MacroSet.Load(C.GetUserFileName(string.Format("mcr{0:#####}.dat", 10 * i + j)), string.Format("Macro Set {0}", j + 1)));
     Books.Add(MB);
       }
       BR.Close();
       return Books.ToArray();
 }
开发者ID:Zastai,项目名称:POLUtils,代码行数:25,代码来源:MacroBook.cs

示例6: Unpack

        static uint HEADER = 0x50414d57; // "WMAP"

        #endregion Fields

        #region Methods

        public static sFolder Unpack(string fileIn, string name)
        {
            name = Path.GetFileNameWithoutExtension(name);

            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            sFolder unpack = new sFolder();
            unpack.files = new List<sFile>();

            if (br.ReadUInt32() != HEADER)
            {
                br.Close();
                br = null;
                throw new FormatException("Invalid header!");
            }

            uint num_files = br.ReadUInt32();
            br.ReadUInt32();    // Unknown 1
            br.ReadUInt32();    // Unknown 2

            for (int i = 0; i < num_files; i++)
            {
                sFile cfile = new sFile();
                cfile.name = name + '_' + i.ToString() + ".bin";
                cfile.offset = br.ReadUInt32();
                cfile.size = br.ReadUInt32();
                cfile.path = fileIn;
                unpack.files.Add(cfile);
            }

            br.Close();
            br = null;
            return unpack;
        }
开发者ID:MetLob,项目名称:tinke,代码行数:39,代码来源:WMAP.cs

示例7: ExamineImage

        public static ImageFileType ExamineImage(string file)
        {
            byte[] magic;

            using (var sr = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                if (sr.BaseStream.Length < 3)
                {
                    sr.Close();
                    return ImageFileType.Invalid;
                }

                magic = sr.ReadBytes(3);

                sr.Close();
            }

            if (magic[0] == 0xFF && magic[1] == 0xD8 && magic[2] == 0xFF)
                return ImageFileType.Jpeg;

            if (magic[0] == 0x89 && magic[1] == 0x50 && magic[2] == 0x4E)
                return ImageFileType.Png;

            return ImageFileType.Invalid;
        }
开发者ID:xupefei,项目名称:Spotlight_Checker,代码行数:25,代码来源:ImageHelper.cs

示例8: BinaryReader_CloseTests

 public void BinaryReader_CloseTests()
 {
     // Closing multiple times should not throw an exception
     using (Stream memStream = CreateStream())
     using (BinaryReader binaryReader = new BinaryReader(memStream))
     {
         binaryReader.Close();
         binaryReader.Close();
         binaryReader.Close();
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:11,代码来源:BinaryReaderTests.cs

示例9: Load

        public static ClipboardBuffer Load(string filename)
        {
            string ext = Path.GetExtension(filename);
            if (string.Equals(ext, ".jpg", StringComparison.InvariantCultureIgnoreCase) || string.Equals(ext, ".png", StringComparison.InvariantCultureIgnoreCase) || string.Equals(ext, ".bmp", StringComparison.InvariantCultureIgnoreCase))
                return LoadFromImage(filename);

            using (var stream = new FileStream(filename, FileMode.Open))
            {
                using (var b = new BinaryReader(stream))
                {

                    string name = b.ReadString();
                    int version = b.ReadInt32();
                    uint tVersion = (uint)version;

                    // check all the old versions
                    if (version < 78)
                    {
                        return Load5(b, name, tVersion, version);
                    }
                    else if (version == 4)
                    {
                        b.Close();
                        stream.Close();
                        return Load4(filename);
                    }
                    else if (version == 3)
                    {
                        b.Close();
                        stream.Close();
                        return Load3(filename);
                    }
                    else if (version == 2)
                    {
                        b.Close();
                        stream.Close();
                        return Load2(filename);
                    }
                    else if (version < 2)
                    {
                        b.Close();
                        stream.Close();
                        return LoadOld(filename);
                    }

                    // not and old version, use new version
                    return LoadV2(b, name, tVersion, version);

                }
            }
        }
开发者ID:Nickakanickiam,项目名称:Terraria-Map-Editor,代码行数:51,代码来源:ClipboardBuffer.File.cs

示例10: SPKImage

		public SPKImage(Palette p, Stream s, int width, int height)
		{
			//int transparent=254;	
			idx = new byte[width*height];
			for(int i=0;i<idx.Length;i++)
				idx[i]=254;

			long pix=0;

			BinaryReader data = new BinaryReader(s);

			try
			{
				while(data.BaseStream.Position < data.BaseStream.Length)
				{
					int cas = data.ReadUInt16();
					switch(cas)
					{
						case 0xFFFF:
						{
							long val = data.ReadUInt16()*2;
							pix+=val;
							break;
						}
						case 0xFFFE:
						{
							long val = data.ReadUInt16()*2;
							while((val--)>0)
							{							
								idx[pix++] = data.ReadByte();							
							}
							break;
						}
						case 0xFFFD:
						{
							image = Bmp.MakeBitmap8(width,height,idx,p.Colors);
							Palette=p;
							data.Close();
							return;
						}
					}
				}
			}
			catch{}

			image = Bmp.MakeBitmap8(width,height,idx,p.Colors);
			Palette=p;
			data.Close();
		}
开发者ID:pmprog,项目名称:OpenXCOM.Tools,代码行数:49,代码来源:SPKImage.cs

示例11: buttonANA_Click

        //////////////////////////////////////////////////////////////////////////////////////////////////////
        // Leer fichero ANA
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        private void buttonANA_Click(object sender, EventArgs e)
        {
            uint anafile_size;
            uint subfiles_count;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Files.Clear(); // Borrar archivos anteriores
                listBox.Items.Clear(); // Borrar lista anterior

                filename = openFileDialog.FileName;
                labelFilename.Text = Path.GetFileName(filename);
                BinaryReader file = new BinaryReader(File.Open(filename, FileMode.Open));

                if (file.ReadUInt32() != 0x414E4140) // 40 41 4E 41
                { MessageBox.Show("Incorrect header. Correct file?"); file.Close(); return; }

                file.ReadUInt32(); // Read (non)padding
                anafile_size = file.ReadUInt32(); // Read ANA size
                file.ReadUInt32(); // Read (non)padding
                subfiles_count = file.ReadUInt32();
                file.ReadUInt32(); file.ReadUInt32(); file.ReadUInt32(); // Read padding
                for (uint i = 0; i < subfiles_count; i++)
                {
                    SubFile temp = new SubFile();
                    temp.offset = file.ReadUInt32();
                    temp.size = file.ReadUInt32();
                    temp.filename = new String(file.ReadChars(8)).Trim('\0');
                    Files.Add(temp);
                    listBox.Items.Add(temp.filename);
                }
                listBox.Sorted = false;
                // Meter el contenido de cada fichero en un buffer, para no liar el reemplazo demasiado
                for (int i = 0; i < Files.Count; i++)
                {
                    file.BaseStream.Seek(Files[i].offset, SeekOrigin.Begin);
                    Files[i].buffer = file.ReadBytes((int)Files[i].size);
                }

                // experimental
                // copiar fragmento ANT a un buffer para luego
                file.BaseStream.Seek(Files[Files.Count - 1].offset + Files[Files.Count - 1].size, SeekOrigin.Begin);
                ant_section = file.ReadBytes((int)file.BaseStream.Length - (int)file.BaseStream.Position);
                // experimental

                file_type = "ana";
                file.Close();
            }
        }
开发者ID:Dahrkael,项目名称:toys,代码行数:52,代码来源:Form1.cs

示例12: isImagePaletted

        public static bool isImagePaletted(string name)
        {
            System.IO.FileStream str1 = new System.IO.FileStream(name, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
            BinaryReader inf = new System.IO.BinaryReader(str1);

            if (inf.BaseStream.Length == 0)
            {
                inf.Close();
                return false;
            }
            int f = inf.ReadInt32();
            inf.Close();

            return f == 0;
        }
开发者ID:KatekovAnton,项目名称:MAX,代码行数:15,代码来源:MaxRes.cs

示例13: Decrypt

        public static void Decrypt(string file_input, string file_output, string key1)
        {
            FileStream input;
            BinaryReader br;
            FileStream output;
            BinaryWriter bw;
            byte[] block;

            key = new Key(key1);
            Utils.key.makeKey();
            Utils.key.reverseKey();
            try
            {
                input = new FileStream(file_input, FileMode.Open, FileAccess.Read);
                br = new BinaryReader(input);
                output = new FileStream(file_output, FileMode.Create, FileAccess.Write);
                bw = new BinaryWriter(output);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            ////
            try
            {
                while ((block = br.ReadBytes(8)).Length > 0)
                {
                    BitArray encrypted_message = Utils.makeMessage(napraw(block));
                    bw.Write((encrypted_message.ToByteArray()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                input.Close();
                output.Close();
                br.Close();
                bw.Close();
            }
            finally
            {
                input.Close();
                output.Close();
                br.Close();
                bw.Close();
            }
        }
开发者ID:WPiotr,项目名称:BSK,代码行数:48,代码来源:Utils.cs

示例14: Load

    public static Shape Load(string fn)
    {
        if (!System.IO.File.Exists(fn))
            throw new System.Exception("File not found: " + fn);

        System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream(fn, System.IO.FileMode.Open));
        Shape s = new Shape();

        s.Width = br.ReadInt32();
        s.Height = br.ReadInt32();
        s.matrix = new bool[s.Width, s.Height];

        try
        {
            for (int x = 0; x < s.Width; x++)
                for (int y = 0; y < s.Height; y++)
                    s.notEmptyCellsCount += (s.matrix[x, y] = br.ReadBoolean()) ? 1 : 0;
        }
        catch (System.IO.EndOfStreamException)
        {
            throw new System.Exception("Invalid data for shape " + fn);
        }

        br.Close();
        s.CreateTexture();
        return s;
    }
开发者ID:GlibBoytsun,项目名称:ShapeRecognition,代码行数:27,代码来源:Shape.cs

示例15: DownLoadFile

        public HttpResponseMessage DownLoadFile(string FileName, string fileType)
        {
            List<String> valores = new List<string>();

            Byte[] bytes = null;
            if (FileName != null)
            {
                string filePath = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), FileName));
                FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                bytes = br.ReadBytes((Int32)fs.Length);

                br.Close();
                fs.Close();
            }

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            System.IO.MemoryStream stream = new MemoryStream(bytes);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue(fileType);
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = FileName
            };

            return (result);
        }
开发者ID:werikaapelfeler,项目名称:ProjetoPI3,代码行数:27,代码来源:FileUploaderController.cs


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