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


C# BinaryReader.Read方法代码示例

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


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

示例1: Load

	public void Load(int Index){
			MemoryMappedFileSecurity CustomSecurity = new MemoryMappedFileSecurity();
CustomSecurity.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType
.Allow));
			using(MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("bits", (long)Math.Ceiling(Length/8.0), MemoryMappedFileAccess.ReadWriteExecute, MemoryMappedFileOptions.None, CustomSecurity, System.IO.HandleInheritability.Inheritable)){
			using (MemoryMappedViewStream stream = mmf.CreateViewStream())
           		{
				int Amount = (int)Math.Ceiling((double)(Length/Int32.MaxValue));
				int Remainder = (int)(Length%Int32.MaxValue);
				int length = (int)(Amount==Index?Math.Ceiling(Remainder/8.0):Math.Ceiling(Int32.MaxValue/8.0));
				byte[] buffer = BitArrayToByteArray(LoadedArray,0,LoadedArray.Length);
				stream.Position=(long)Math.Ceiling((Int32.MaxValue/8.0))*LoadedArrayIndex;
                		BinaryWriter writer = new BinaryWriter(stream);
				writer.Write(buffer);
				stream.Position=0;//(long)Math.Ceiling((Int32.MaxValue/8.0))*Index;
				BinaryReader reader = new BinaryReader(stream);
				buffer = new byte[(int)Math.Ceiling((Int32.MaxValue/8.0))];
				try{reader.Read(buffer,(int)Math.Ceiling((Int32.MaxValue/8.0))*Index,(int)Math.Ceiling((Int32.MaxValue/8.0)));} catch{LoadedArray = new BitArray((int)(length*8.0));}
           		}
			}
			//int ElementIndex = (int)Math.Floor((double)(T/Int32.MaxValue));
			//int Index = (int)(T%Int32.MaxValue);
			//Elements[ElementIndex][Index]=value;
		//}
	}
开发者ID:thedanieldude1,项目名称:DanielCode,代码行数:25,代码来源:64bitCollection.cs

示例2: getNextMessage

	/**
	 * Gets the next message from an input stream. Crudely, this method keeps
	 * reading lines from the stream until it finds one that contains the string
	 * "&lt;/message&gt;". It ignores lines with elements called "&lt;trace&gt;"
	 * or "&lt;/trace&gt;". It returns null if it does not read anything.
	 * 
	 * @param dis
	 *          A data input stream, corresponding to some opened file
	 * @return A string corresponding to the next message, or null if no message
	 *         could be read
	 */
	private static string getNextMessage(BinaryReader br)
	{
		string message = "";
		
		try
		{
			while (br.Read() != 0)
			{
				string line = br.ReadString();
				
				line = line.Trim();
				
				if (line.IndexOf("<Trace>") != -1 || 
					line.IndexOf("</Trace>") != -1)
				{
					continue;
				}
				
				message += line;
				
				if (line.IndexOf("</Event>") != -1)
				{
					break;
				}
			}
		}
		
		catch (IOException o)
		{
			System.Diagnostics.Debug.Print (o.ToString());
			return null;
		}
		
		return message;
	}
开发者ID:sylvainhalle,项目名称:BeepBeepCSharp,代码行数:46,代码来源:BeepBeepValidator.cs

示例3: ReadMp3TagFromFile

    public void ReadMp3TagFromFile(string path)
    {
        var buffer = new char[ ID3TagLength ];

        // Open file
        using ( var binReader = new BinaryReader( File.Open( path, FileMode.Open ) ) ) {
            // Take last 128 bytes in
            binReader.BaseStream.Seek( -ID3TagLength, SeekOrigin.End );
            int bytesRead = binReader.Read( buffer, 0, ID3TagLength );

            if ( bytesRead == ID3TagLength ) {
                string tagMark = new string( buffer, 0, 3 );

                if ( tagMark == ID3TagMark ) {
                    // Read the ID3 tag data
                    edTitle.Text = ( new string( buffer, 3, 30 ) ).Trim();
                    edAuthor.Text = ( new string( buffer, 33, 30 ) ).Trim();
                    edAlbum.Text = ( new string( buffer, 63, 30 ) ).Trim();
                    edYear.Text =  ( new string( buffer, 93, 4 ) ).Trim();
                }
            }
        }

        return;
    }
开发者ID:Baltasarq,项目名称:charlacsharpmonodevelop,代码行数:25,代码来源:MainWindow.cs

示例4: TestStreams

                public void TestStreams()
                {
                    Variant dict = new Variant(Variant.EnumType.Dictionary);
                    dict.Add("key1", new Variant("value1"));
                    dict.Add("key2", new Variant("value2"));

                    Variant input = new Variant(Variant.EnumType.List);
                    for (int i = 0; i < 10000; ++i)
                    {
                        input.Add(dict);
                    }

                    System.IO.MemoryStream istream = new System.IO.MemoryStream();
                    using(BinaryWriter writer = new BinaryWriter(istream))
                    {
                        writer.Write(input);
                    }

                    Variant output;
                    System.IO.MemoryStream ostream = new System.IO.MemoryStream(istream.GetBuffer());
                    using (BinaryReader reader = new BinaryReader(ostream))
                    {
                        output = reader.Read();
                    }

                    Assert.True(input.Equals(output));
                }
开发者ID:rokstrnisa,项目名称:protean,代码行数:27,代码来源:TestBinaryStreams.cs

示例5: Main

 public static void Main()
 {
     char[] e=new char[20000];
     var b=new BinaryReader(new BufferedStream(Console.OpenStandardInput()));
     var h=b.Read(e,0,20000);
     var z=(new S(e,0,h)).Split(null);
     var d=new System.Collections.Generic.Dictionary<S,S>();
     S s="",t=s,r,x;
     int i,j;
     if(z[0]=="6")
         C.Write("fdkjnvqaqvnjkdf");
     else if(z[0]=="1")
         C.Write(z[1]);
     else if(z[0]=="7")
         for(i=0;i<7;i++)
             C.Write(z[1]);
     else
     {
         Array.Sort(z,1,z.Length-1);
         for(i=1;i<z.Length;i++)
         {
             x=z[i];
             r=new S(x.Reverse().ToArray());
             j=Array.IndexOf(z,r,i+1);
             if(j>0)
             {
                 s+=x;
                 t=r+t;
                 z[i]=z[j]="";
             }
         }
         C.Write(s+t);
     }
 }
开发者ID:neetsdkasu,项目名称:Paiza-POH-MyAnswers,代码行数:34,代码来源:test2.cs

示例6: FromBytes

 public static Variant FromBytes(byte[] bytes, BinaryMode mode, IVariantObjectFactory factory)
 {
     using (MemoryStream ms = new MemoryStream(bytes))
     {
         BinaryReader reader = new BinaryReader(ms, mode, factory);
         return reader.Read();
     }
 }
开发者ID:proteanic,项目名称:protean,代码行数:8,代码来源:BinaryReader.cs

示例7: Read

    public static double[][] Read(string fileName, out int sampFreq)
    {
        using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
        {
            using (BinaryReader br = new BinaryReader(fs))
            {
                if (br.ReadInt32() != RiffHeader)
                {
                    throw new Exception("WAVファイルじゃない\(^o^)/");
                }
                br.ReadInt32();
                if (br.ReadInt32() != WaveHeader)
                {
                    throw new Exception("WAVファイルじゃない\(^o^)/");
                }

                while (br.ReadInt32() != FmtHeader)
                {
                    br.BaseStream.Seek(br.ReadInt32() + 1 >> 1 << 1, SeekOrigin.Current);
                }

                int numChannels;
                {
                    byte[] chunk = new byte[br.ReadInt32()];
                    br.Read(chunk, 0, chunk.Length);
                    ReadFmtChunk(chunk, out numChannels, out sampFreq);
                    if ((chunk.Length & 1) > 0) br.ReadByte();
                }

                while (br.ReadInt32() != DataHeader)
                {
                    br.BaseStream.Seek(br.ReadInt32() + 1 >> 1 << 1, SeekOrigin.Current);
                }

                {
                    byte[] chunk = new byte[br.ReadInt32()];
                    br.Read(chunk, 0, chunk.Length);
                    return ReadDataChunk(chunk, numChannels);
                }
            }
        }
    }
开发者ID:sinshu,项目名称:wav_utility,代码行数:42,代码来源:WavUtil.cs

示例8: ConversionImagen

    public byte[] ConversionImagen(string nombrearchivo)
    {
        FileStream fs = new FileStream(nombrearchivo, FileMode.Open);

        BinaryReader br = new BinaryReader(fs);
        byte[] imagen = new byte[(int)fs.Length];
        br.Read(imagen, 0, (int)fs.Length);
        br.Close();
        fs.Close();
        return imagen;
    }
开发者ID:jquirogadesarrollador,项目名称:Varu_Original,代码行数:11,代码来源:InformesClientes.aspx.cs

示例9: decode

    public ItemQuote decode(Stream wire)
    {
        BinaryReader src = new BinaryReader(new BufferedStream(wire));

        long itemNumber = IPAddress.NetworkToHostOrder(src.ReadInt64());
        int quantity = IPAddress.NetworkToHostOrder(src.ReadInt32());
        int unitPrice = IPAddress.NetworkToHostOrder(src.ReadInt32());
        byte flags = src.ReadByte();

        int stringLength = src.Read(); // Returns an unsigned byte as an int
        if (stringLength == -1)
          throw new EndOfStreamException();
        byte[] stringBuf = new byte[stringLength];
        src.Read(stringBuf, 0, stringLength);
        String itemDesc = encoding.GetString(stringBuf);

        return new ItemQuote(itemNumber,itemDesc, quantity, unitPrice,
          ((flags & ItemQuoteBinConst.DISCOUNT_FLAG) == ItemQuoteBinConst.DISCOUNT_FLAG),
          ((flags & ItemQuoteBinConst.IN_STOCK_FLAG) == ItemQuoteBinConst.IN_STOCK_FLAG));
    }
开发者ID:jin55132,项目名称:TCPCSharp,代码行数:20,代码来源:ItemQuoteDecoderBin.cs

示例10: Read

	public byte Read(long T,MemoryMappedViewStream stream){

				byte[] buffer = new byte[1];
                		BinaryReader reader = new BinaryReader(stream);
     				try{reader.Read(buffer,(int)Math.Floor(T/8.0),1);}
				catch{return default(byte);}
				
				return buffer[0];
           		
			
	}
开发者ID:thedanieldude1,项目名称:DanielCode,代码行数:11,代码来源:64bitCollection.cs

示例11: Page_Load

	protected void Page_Load (object sender, EventArgs e)
	{
		// Console.WriteLine ("MoonLogProvider");
		try {
			string filename, directory, path;
			byte [] bytes = new byte [1024];
			int read;

			if (Request.HttpMethod != "POST") {
				Log ("MoonLogProvider: Invalid method. Expected 'POST'.");
				return;
			}
			
			filename = Request ["filename"];
			directory = Environment.GetEnvironmentVariable ("MOONLIGHT_UNIT_HARNESS_LOG_DIRECTORY");
			
			if (string.IsNullOrEmpty (directory) && Environment.OSVersion.Platform == PlatformID.Win32NT)
				directory = @"C:\";

			if (string.IsNullOrEmpty (directory)) {
				directory = Environment.CurrentDirectory;
				Log ("MoonLogProvider: No log directory was set with MOONLIGHT_UNIT_HARNESS_LOG_DIRECTORY, writing to current directory '{0}'.", directory);
			}

			if (string.IsNullOrEmpty (filename)) {
				Log ("MoonLogProvider: No log file was provided.");
				return;
			}

			if (filename.IndexOfAny (Path.GetInvalidFileNameChars ()) != -1) {
				Log ("MoonLogProvider: The filename '{0}' contains invalid characters.", filename);
				return;
			}

			path = Path.Combine (directory, filename);
			
			Log ("MoonLogProvider: Saving file to: {0}", path);
			
			using (BinaryReader reader = new BinaryReader (Request.InputStream)) {
				using (FileStream fs = new FileStream (path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) {
					while (true) {
						read = reader.Read (bytes, 0, bytes.Length);
						// Log ("MoonLogProvider: Read {0} bytes.", read);
						// Log ("Read: {0}", System.Text.ASCIIEncoding.ASCII.GetString (bytes, 0, read));
						if (read == 0)
							break;
						fs.Write (bytes, 0, read);
					}
				}
			}
		} catch (Exception ex) {
			Log ("MoonLogProvider: Exception while handling log message: {0}", ex.ToString ());
		}
	}
开发者ID:dfr0,项目名称:moon,代码行数:54,代码来源:MoonLogProvider.aspx.cs

示例12: GetFileByteData

    public static byte[] GetFileByteData(String fileName)
    {

        FileStream fs = new FileStream(fileName, FileMode.Open);
        BinaryReader br = new BinaryReader(fs);

        byte[] testArray = new byte[fs.Length];
        int count = br.Read(testArray, 0, testArray.Length);

        br.Close();

        return testArray;
    }
开发者ID:wra222,项目名称:testgit,代码行数:13,代码来源:ProcessDownloadFile.aspx.cs

示例13: Fetch

 public Crawler Fetch()
 {
     if (!IsExternalIPAddress(this.SourceUrl))
     {
         State = "INVALID_URL";
         return this;
     }
     var request = HttpWebRequest.Create(this.SourceUrl) as HttpWebRequest;
     using (var response = request.GetResponse() as HttpWebResponse)
     {
         if (response.StatusCode != HttpStatusCode.OK)
         {
             State = "Url returns " + response.StatusCode + ", " + response.StatusDescription;
             return this;
         }
         if (response.ContentType.IndexOf("image") == -1)
         {
             State = "Url is not an image";
             return this;
         }
         ServerUrl = PathFormatter.Format(Path.GetFileName(this.SourceUrl), Config.GetString("catcherPathFormat"));
         var savePath = Request.MapPath(ServerUrl);
         if (!Directory.Exists(Path.GetDirectoryName(savePath)))
         {
             Directory.CreateDirectory(Path.GetDirectoryName(savePath));
         }
         try
         {
             var stream = response.GetResponseStream();
             var reader = new BinaryReader(stream);
             byte[] bytes;
             using (var ms = new MemoryStream())
             {
                 byte[] buffer = new byte[4096];
                 int count;
                 while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
                 {
                     ms.Write(buffer, 0, count);
                 }
                 bytes = ms.ToArray();
             }
             File.WriteAllBytes(savePath, bytes);
             State = "SUCCESS";
         }
         catch (Exception e)
         {
             State = "抓取错误:" + e.Message;
         }
         return this;
     }
 }
开发者ID:Feng2012,项目名称:LoTCodeBase,代码行数:51,代码来源:CrawlerHandler.cs

示例14: saveFile

    public bool saveFile(HttpContext context, string targetFile)
    {
        var request = context.Request;
        byte[] buffer = new byte[request.ContentLength];
        using (BinaryReader br = new BinaryReader(request.InputStream))
            br.Read(buffer, 0, buffer.Length);

        FileStream fs = new FileStream(targetFile, FileMode.Create,
            FileAccess.ReadWrite);
        BinaryWriter bw = new BinaryWriter(fs);
        bw.Write(buffer);
        bw.Close();
        return true;
    }
开发者ID:hmarinho,项目名称:Master,代码行数:14,代码来源:FileUpload.cs

示例15: Open

    public static GOBFile Open(string path)
    {
        //Debug.Log("GOBFile.Open(" + path + ")");
        FileStream fs = null;
        try { fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); } catch {}
        if (fs == null) {
            Debug.LogError("OpenRead(\"" + path + "\") failed.");
            return null;
        }

        BinaryReader br = new BinaryReader(fs);

        try {
            byte[] id = new byte[4];
            if (br.Read(id, 0, 4) != 4) {
                Debug.LogError("Failed to read GOB header in file " + path + ".");
                fs.Close();
                return null;
            }

            if ((id[0] != 71) || (id[1] != 79) || (id[2] != 66) || (id[3] != 0xA)) {
                fs.Close();
                Debug.LogError("\"" + path + "\" is not a GOB file.");
                return null;
            }

            int dirOfs = br.ReadInt32();

            br.BaseStream.Position = (long)dirOfs;

            int numFiles = br.ReadInt32();

            GOBFile gob = new GOBFile();
            byte[] name = new byte[13];
            for (int i = 0; i < numFiles; ++i) {
                File file = File.Read(br, name);
                gob._dir.Add(file.Name, file);
                // Debug.Log (file.Name);
            }

            gob._file = br;
            return gob;
        } catch  {
            using (br) {}
        }

        return null;
    }
开发者ID:joeriedel,项目名称:DarkForcesUnity,代码行数:48,代码来源:GOBFile.cs


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