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


C# System.IO.Write方法代码示例

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


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

示例1: SendHandshake

		public static void SendHandshake(IO.Stream stream, ByteField20 infoDigest)
		{
			stream.WriteByte((byte)protocolString.Length);
			stream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(protocolString), 0, protocolString.Length);

			// 8 zeros
			stream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 8);

			// SHA digest
			stream.Write(infoDigest.Data, 0, infoDigest.Data.Length);
		}
开发者ID:peteward44,项目名称:torrent.net,代码行数:11,代码来源:peerprotocol.cs

示例2: SendPeerId

		public static void SendPeerId(IO.Stream netStream, ByteField20 peerId)
		{
			netStream.Write(peerId.Data, 0, peerId.Data.Length);
		}
开发者ID:peteward44,项目名称:torrent.net,代码行数:4,代码来源:peerprotocol.cs

示例3: SendBitfieldMessage

		public static void SendBitfieldMessage(IO.Stream stream, DownloadFile downloadFile)
		{
			int bitfieldLength = downloadFile.Bitfield.Count/8 + ((downloadFile.Bitfield.Count % 8) > 0 ? 1 : 0);
			byte[] bitfield = new byte[bitfieldLength];
			downloadFile.Bitfield.CopyTo(bitfield, 0);
			SendMessageHeader(stream, PeerMessage.Bitfield, bitfieldLength);
			stream.Write(bitfield, 0, bitfield.Length);
		}
开发者ID:peteward44,项目名称:torrent.net,代码行数:8,代码来源:peerprotocol.cs

示例4: WriteInt

		// i would use IO.BinaryWriter but that caused problems
		private static void WriteInt(IO.Stream stream, int val)
		{
			byte[] b = new byte[4];
			b[3] = (byte)(val & 0x000000FF);
			b[2] = (byte)((val & 0x0000FF00) >> 8);
			b[1] = (byte)((val & 0x00FF0000) >> 16);
			b[0] = (byte)((val & 0xFF000000) >> 24);
			stream.Write(b, 0, b.Length);
//			stream.Write(System.BitConverter.GetBytes(val), 0, 4);
		}
开发者ID:peteward44,项目名称:torrent.net,代码行数:11,代码来源:peerprotocol.cs

示例5: LoadFromFile

		/// <summary>
		/// Loads a piece from the torrent. The torrent piece must already have been downloaded (ie exists in the bitfield)
		/// </summary>
		/// <param name="pieceId">Piece index to load from</param>
		/// <param name="ostream">Stream to save to</param>
		/// <returns>True if the piece was loaded succesfully, false otherwise</returns>
		public bool LoadFromFile(int pieceId, IO.Stream ostream)
		{
			if (!this.piecesDownloaded.Get(pieceId))
				return false;
			else
			{
				int dataRead = 0;
				int positionInFile = 0;
				int fileNum = 0;
				
				WhichFileIsPieceIn(pieceId, out fileNum, out positionInFile);

				while (dataRead < this.infofile.GetPieceLength(pieceId) && fileNum < this.infofile.FileCount)
				{
					int fileLength = this.infofile.GetFileLength(fileNum);
					int dataToRead = System.Math.Min(fileLength - positionInFile, this.infofile.GetPieceLength(pieceId) - dataRead);

					IO.FileStream fstream = new IO.FileStream(this.infofile.GetFileName(fileNum), IO.FileMode.Open);

					// read data from the file
					fstream.Seek(positionInFile, IO.SeekOrigin.Begin);
					
					byte[] data = new byte[ dataToRead ];
					fstream.Read(data, 0, data.Length);
					ostream.Write(data, 0, data.Length);
					dataRead += dataToRead;

					fstream.Close();

					fileNum++; // move onto next file
					positionInFile = 0;
				}
				
				return true;
			}
		}
开发者ID:peteward44,项目名称:torrent.net,代码行数:42,代码来源:downloadfile.cs

示例6: Read

		/// <summary>Reads data from the piece</summary>
		/// <param name="stream">Data to read into</param>
		/// <param name="length">Amount of data to read</param>
		/// <param name="poffset">Offset within the piece to read data from</param>
		public void Read(IO.Stream stream, int length, int poffset)
		{
			byte[] tdata = new byte[length];
			this.Read(tdata, 0, length, poffset);
			stream.Write(tdata, 0, length);
		}
开发者ID:peteward44,项目名称:torrent.net,代码行数:10,代码来源:piece.cs


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