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


C# BinaryWriter.Seek方法代码示例

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


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

示例1: Main

    public static void Main() {
        var ms = new MemoryStream();
        ms.Write(new byte[] { 0, 1, 2, 3 }, 0, 4);
        PrintStatus(ms);

        using (var bw = new BinaryWriter(ms)) {
            bw.Seek(1, SeekOrigin.Begin);
            PrintStatus(ms);
            bw.Seek(1, SeekOrigin.End);
            PrintStatus(ms);
        }
    }
开发者ID:GlennSandoval,项目名称:JSIL,代码行数:12,代码来源:BinaryWriterSeek.cs

示例2: Write

	public void Write (float[] clipData, WaveFormatChunk format, FileStream stream)
	{
		WaveHeader header = new WaveHeader ();
		WaveDataChunk data = new WaveDataChunk ();
		
		data.shortArray = new short[clipData.Length];
		for (int i = 0; i < clipData.Length; i++)
			data.shortArray [i] = (short)(clipData [i] * 32767);
		
		data.dwChunkSize = (uint)(data.shortArray.Length * (format.wBitsPerSample / 8));
		
		BinaryWriter writer = new BinaryWriter (stream);
		writer.Write (header.sGroupID.ToCharArray ());
		writer.Write (header.dwFileLength);
		writer.Write (header.sRiffType.ToCharArray ());
		writer.Write (format.sChunkID.ToCharArray ());
		writer.Write (format.dwChunkSize);
		writer.Write (format.wFormatTag);
		writer.Write (format.wChannels);
		writer.Write (format.dwSamplesPerSec);
		writer.Write (format.dwAvgBytesPerSec);
		writer.Write (format.wBlockAlign);
		writer.Write (format.wBitsPerSample);
		writer.Write (data.sChunkID.ToCharArray ());
		writer.Write (data.dwChunkSize);
		foreach (short dataPoint in data.shortArray) {
			writer.Write (dataPoint);
		}
		writer.Seek (4, SeekOrigin.Begin);
		uint filesize = (uint)writer.BaseStream.Length;
		writer.Write (filesize - 8);
		writer.Close ();
	}
开发者ID:SnotE101,项目名称:ATT_APIPlatform_Unity_SDK,代码行数:33,代码来源:WaveGen.cs

示例3: iPhoneVersionHeader

	static byte[] iPhoneVersionHeader()
	{
		byte[] bVersionHeader = new byte[20];
		MemoryStream MS = new System.IO.MemoryStream(bVersionHeader);
		BinaryWriter BW = new BinaryWriter(MS);
		BW.Seek(4, SeekOrigin.Begin);
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)20));
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)1));
		BW.Close();
		MS.Close();
		return bVersionHeader;
	}
开发者ID:jakubl,项目名称:jphonewin,代码行数:12,代码来源:iphone.cs

示例4: USBMUXConnection

	// A USBMUX connection is created for each port that will be used for communication.
	// For instance, one will be created on port 0xF27E for the lockdown protocol.
	// Communications are all prefaced by a TCP-like packet header that is managed on a
	// per-connection basis by this class.
	public USBMUXConnection(iPhoneWrapper IPW, ushort SPort, ushort DPort)
	{
		if (IPW == null || !IPW.Usable) throw new Exception("No device ready in USBMUXConnection constructor.");
		if (SPort == 0 || DPort == 0) throw new Exception("Need non-zero ports to create USBMUXConnection");

		iPhone = IPW;
		BufferedPacketsWaiting = new Queue<byte[]>();
		SourcePort = SPort;
		DestPort = DPort;
		SentCount = 0;
		ReceivedCount = 0;

		// Initialize packet header for SYN step of handshake.
		byPacketHeader = new byte[28];
		MemoryStream MS = new MemoryStream(byPacketHeader);
		BinaryWriter BW = new BinaryWriter(MS);
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)6)); // Type
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)28)); // Length
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)SourcePort)); // Source port
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)DestPort)); // Destination port
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)SentCount)); // Self Count
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((int)ReceivedCount)); // OCnt
		BW.Write((byte)0x50); // Offset
		BW.Write((byte)2); // TCP Flag = SYN
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)0x0200)); // Window size
		BW.Seek(2, SeekOrigin.Current); // Always zero
		BW.Write(System.Net.IPAddress.HostToNetworkOrder((short)28)); // Length16
		BW.Close();
		MS.Close();

		// Initiate handshake: send SYN.
		if (SendHeader() < 0)
			throw new Exception("Failed to send SYN");

		// Continue handshake: receive SYNACK.
		byte[] byResponse = iPhone.ReceiveFromiPhone();
		if (byResponse == null || byResponse.Length != 28 || byResponse[0x15] != 0x12)
			throw new Exception("Expected SYNACK, got something else.");

		byPacketHeader[0x15] = 0x10;
		SentCount = 1;
		ReceivedCount = 1;
	}
开发者ID:jakubl,项目名称:jphonewin,代码行数:47,代码来源:iphone.cs

示例5: SaveLevel

    private static void SaveLevel(Constants.Levels level, RankingData data)
    {
        using (BinaryWriter bw = new BinaryWriter(File.OpenWrite("Data/ranking.dat")))
        {
            bw.Seek(24 * (int)level + 4, SeekOrigin.Begin);

            for (int i = 0; i < RankingData.MaxEntries; i++)
            {
                string name = StringTool.Truncate (data.Ranks [(int)IORanking.Ranking.BestScore].Name [i], 20);
                bw.Write (Encoding.ASCII.GetBytes (name));
                bw.Write (new byte[20 - name.Length]);
                bw.Write (data.Ranks [(int)IORanking.Ranking.BestScore].Score [i]);
            }

            for (int i = 0; i < RankingData.MaxEntries; i++)
            {
                string name = StringTool.Truncate (data.Ranks [(int)IORanking.Ranking.BestTime].Name [i], 20);
                bw.Write (Encoding.ASCII.GetBytes (name));
                bw.Write (new byte[20 - name.Length]);
                bw.Write (data.Ranks [(int)IORanking.Ranking.BestTime].Score [i]);
            }

            for (int i = 0; i < RankingData.MaxEntries; i++)
            {
                string name = StringTool.Truncate (data.Ranks [(int)IORanking.Ranking.BestScoreTime].Name [i], 20);
                bw.Write (Encoding.ASCII.GetBytes (name));
                bw.Write (new byte[20 - name.Length]);
                bw.Write (data.Ranks [(int)IORanking.Ranking.BestScoreTime].Score [i]);
            }

            bw.Close ();
        }

        return;
    }
开发者ID:guilherme-gm,项目名称:rollaball,代码行数:35,代码来源:IORanking.cs

示例6: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BinaryReader sr2;
			BinaryWriter sw2;
			FileStream fs2;
			String filName = s_strTFAbbrev+"Test.tmp";
			if(File.Exists(filName))
				File.Delete(filName);			
			strLoc = "Loc_9577b";
			fs2 = new FileStream(filName, FileMode.Create);
			sw2 = new BinaryWriter(fs2);
			sw2.Write("Dette er sjef");
			sw2.Close();
			strLoc = "Loc_49t8e";
			fs2 = new FileStream(filName, FileMode.Open);
			sw2 = new BinaryWriter(fs2);
			sw2.Close();
			sw2.Close();
			sw2.Close();
			iCountTestcases++;
			try {
				sw2.Seek(1, SeekOrigin.Begin);
				iCountErrors++;
				printerr( "Error_687yv! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_y67y9! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_9y7g7! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sw2.Write(new Byte[2], 0, 2);
				iCountErrors++;
				printerr( "Error_9177g! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_80093! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_7100b! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sw2.Write(new Char[2], 0, 2);
				iCountErrors++;
				printerr( "Error_2398j! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_t877b! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_787yb! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sw2.Write(true);
				iCountErrors++;
				printerr( "Error_10408! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_1098t! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_178t5! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sw2.Write((Byte)4);
				iCountErrors++;
				printerr( "Error_17985! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_0984s! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_019g8! Incorrect exception thrown, excc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sw2.Write(new Byte[]{1,2});
				iCountErrors++;
				printerr( "Error_10989! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_01099! Caught expectede exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_16794! Incorrect exception thrown, exc=="+exc.ToString());
			} 
			iCountTestcases++;
			try {
				sw2.Write('a');
				iCountErrors++;
				printerr( "ERror_1980f! Expected Exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_1099g! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5741close.cs

示例7: Main

    static void Main(string[] args)
    {
        if ( args.Length != 3 ) {
            Console.Error.WriteLine("Usage: mono tftp.exe [error|noerror] host file");
            Environment.Exit(1);
        }

        int port = 7000;
        bool error = false;
        string host = args[1];
        string file = args[2];

        if ( args[0].Equals("error") )
            error = true;
        else if ( args[0].Equals("noerror") )
            error = false;
        else {
            Console.Error.WriteLine("Must specify error or noerror.");
            Environment.Exit(1);
        }

        int pos = 0;
        FileStream fs = new FileStream(file, FileMode.Create);
        BinaryWriter bw = new BinaryWriter(fs);
        UdpClient client = new UdpClient(host, port);
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

        byte[] request = Request(file, error);
        client.Send(request, request.Length);

        while ( true ) {
            byte[] receive = client.Receive(ref RemoteIpEndPoint);

            if ( receive[1] == 5 ) Error(receive);	// Check for an error message (opcode 05).

            byte[] decoded = Decode(receive);
            byte[] block = new byte[] { receive[2], receive[3] };

            if ( decoded == null )
                client.Send(Nack(block), 4);
            else {
                bw.Seek(pos, 0);
                bw.Write(decoded);
                bw.Flush();
                pos += decoded.Length;
                client.Send(Ack(block), 4);
                if ( receive.Length < 516 ) break;	// Last block is smaller than max (516).
            }
        }
    }
开发者ID:PastyPilgrim,项目名称:datacomm,代码行数:50,代码来源:tftp.cs

示例8: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
        int[] iArrInvalidValues = new Int32[]{ -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, Int32.MinValue, Int16.MinValue};
        int[] iArrLargeValues = new Int32[]{ 10000, 100000 , Int32.MaxValue/200 , Int32.MaxValue/1000, Int16.MaxValue, Int32.MaxValue, Int32.MaxValue-1, Int32.MaxValue/2 , Int32.MaxValue/10 , Int32.MaxValue/100 };
		try
		{		
			BinaryWriter dw2 = null;
			MemoryStream mstr = null;
			Byte[] bArr = null;
			StringBuilder sb = new StringBuilder();
			Int64 lReturn = 0;
			strLoc = "Loc_278yg";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			dw2.Write("Hello, this is my string".ToCharArray());
			iCountTestcases++;
            for(int iLoop = 0 ; iLoop < iArrInvalidValues.Length ; iLoop++ ){
    			try {
    				lReturn = dw2.Seek(iArrInvalidValues[iLoop], SeekOrigin.Begin);
    				iCountErrors++;
    				printerr( "Error_17dy7! Expected exception not thrown");
    			} catch (IOException ) {
    			} catch (Exception exc) {
    				iCountErrors++;
    				printerr( "Error_918yc! Incorrect exception thrown, exc=="+exc.ToString());
    			}
    			if(lReturn != 0) {
    				iCountErrors++;
    				printerr( "Error_2t8gy! Incorrect return value, lReturn=="+lReturn);
    			}
            }
            dw2.Close(); 
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			dw2.Write("Hello, this is my string".ToCharArray());
			iCountTestcases++;
            for(int iLoop = 0 ; iLoop < iArrLargeValues.Length ; iLoop++ ){
    			try {
    				lReturn = dw2.Seek(iArrLargeValues[iLoop], SeekOrigin.Begin);
                    if(lReturn != iArrLargeValues[iLoop]) {
                        iCountErrors++;
                        printerr( "Error_43434! Incorrect return value, lReturn=="+lReturn);
                    }
    			} catch (Exception exc) {
    				iCountErrors++;
    				printerr( "Error_9880! Incorrect exception thrown, exc=="+exc.ToString());
    			}
            }
            dw2.Close(); 
			strLoc = "Loc_093uc";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			dw2.Write("012345789".ToCharArray());
			iCountTestcases++;
			try {
				lReturn = dw2.Seek(3, ~SeekOrigin.Begin);
				iCountErrors++;
				printerr( "Error_109ux! Expected exception not thrown");
			} catch (ArgumentException) {
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_190x9! Incorrect exception thrown, exc=="+exc.ToString());
			}
			dw2.Close();
			strLoc = "Loc_98yct";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			dw2.Write("0123456789".ToCharArray());
			lReturn = dw2.Seek(0, SeekOrigin.Begin);
			iCountTestcases++;
			if(lReturn != 0) { 
				iCountErrors++;
				printerr( "Error_9t8vb! Incorrect return value, lReturn=="+lReturn);
			} 
			dw2.Write("lki".ToCharArray());
			dw2.Flush();
			bArr = mstr.ToArray();
			sb = new StringBuilder();
			for(int i = 0 ; i < bArr.Length ; i++)
				sb.Append((Char)bArr[i]);
			iCountTestcases++;
			if(!sb.ToString().Equals("lki3456789")) {
				iCountErrors++;
				printerr( "Error_837sy! Incorrect sequence in stream, sb=="+sb.ToString());
			}
			dw2.Close();
			strLoc = "Loc_29hxs";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			dw2.Write("0123456789".ToCharArray());
			lReturn = dw2.Seek(3, SeekOrigin.Begin);
			iCountTestcases++;
			if(lReturn != 3) {
				iCountErrors++;
				printerr( "Error_209gu! Incorrect return value, lReturn=="+lReturn);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5561seek_i_so.cs

示例9: SetBoolValue

    public static bool SetBoolValue(string ValueName, bool ValueToSet, string ConfigFileName)
    {
        try
        {
            string SettingsPath = Application.dataPath.Remove(Application.dataPath.LastIndexOf("/")) + "/ProjectSettings/" + ConfigFileName + ".asset";

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

            // Read the unsigned int at offset 0x0C in the file.
            // This contains the offset at which the setting's numerical values are stored.
            br.BaseStream.Seek(0x0C, SeekOrigin.Begin);

            // For some reason, the offset is Big Endian in the file.
            int SettingsOffset = GetBigEndianIntFromBinaryReader(br);

            // In the file, we start with 0x14 bytes, then a string containing the unity version,
            // then 0x0C bytes, then a string containing the base class name, followed by a string containing "base".
            string tempStr;
            br.BaseStream.Seek(0x14, SeekOrigin.Begin);
            tempStr = GetStringFromBinaryReader(br); // Unity Version
            br.BaseStream.Seek(0x0C, SeekOrigin.Current);
            tempStr = GetStringFromBinaryReader(br); // Config file Name
            if (tempStr != ConfigFileName)
            {
                // File format has changed, return error
                return false;
            }

            tempStr = GetStringFromBinaryReader(br); // "Base"
            if (tempStr != "Base")
            {
                // File format has changed, return error
                return false;
            }

            // This string is then followed by 24 bytes
            br.BaseStream.Seek(24, SeekOrigin.Current);

            // We then have a series of String (type), String (variable name), and 24 bytes
            // We can use the type of the settings before the field we are looking for to
            // find its offset after SettingsOffset.
            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                string SettingType = GetStringFromBinaryReader(br);
                string SettingName = GetStringFromBinaryReader(br);

                if (SettingName == ValueName)
                {
                    break;
                }

                br.BaseStream.Seek(24, SeekOrigin.Current);

                if (GetSizeofTypeByString(SettingType) == -1)
                {
                    // File format has changed, return error
                    return false;
                }

                SettingsOffset += GetSizeofTypeByString(SettingType);
            }

            // Set the setting in the file
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Seek(SettingsOffset, SeekOrigin.Begin);
            bw.Write(ValueToSet ? (byte)1 : (byte)0);
            bw.Close();
            fs.Close();
        }
        catch (Exception)
        {
            // Error happened
            return false;
        }

        // Success!
        return true;
    }
开发者ID:TheWanderingTree,项目名称:temple,代码行数:81,代码来源:AkUnitySettingsParser.cs

示例10: WriteSaveData

 private static void WriteSaveData(Action<Action<int, byte[]>> writeActions)
 {
     using (var file = new BinaryWriter(File.Open(GetFilePath(), FileMode.OpenOrCreate, FileAccess.Write)))
     {
         writeActions((offset, data) =>
         {
             if (data != null)
             {
                 file.Seek(offset, SeekOrigin.Begin);
                 file.Write(data);
             }
         });
     }
 }
开发者ID:Skaarah,项目名称:Launcher,代码行数:14,代码来源:MekaPlayerPrefs.cs

示例11: DrawImage

	private void DrawImage(VideoFrameType type)
	{
		Stream str = new MemoryStream();
		BinaryWriter writer = new BinaryWriter(str);
		// LITTLE ENDIAN!!
		writer.Write(new byte[] { 0x42, 0x4D });
		writer.Write((int)(type.managedData.Length + 0x36));
		writer.Write((int)0);
		writer.Write((int)0x36);
		writer.Write((int)40);
		writer.Write((int)type.width);
		writer.Write((int)type.height);
		writer.Write((short)1);
		writer.Write((short)24);
		writer.Write((int)0);
		writer.Write((int)type.managedData.Length);
		writer.Write((int)3780);
		writer.Write((int)3780);
		writer.Write((int)0);
		writer.Write((int)0);
		for (int y = type.height - 1; y >= 0; y--)
			writer.Write(type.managedData, y * type.linesize, type.width * 3);
		writer.Flush();
		writer.Seek(0, SeekOrigin.Begin);
		Bitmap bitmap = new Bitmap(str);
		g.DrawImage(bitmap, 0, 0, mainDraw.WidthRequest, mainDraw.HeightRequest);
		writer.Close();

	}
开发者ID:crazyender,项目名称:FFMPEG.net,代码行数:29,代码来源:MainWindow.cs


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