本文整理汇总了C#中System.IO.BinaryWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.Write方法的具体用法?C# BinaryWriter.Write怎么用?C# BinaryWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BwWriteLE4
// DSFチャンクの数字はリトルエンディアンバイトオーダー
private void BwWriteLE4(BinaryWriter bw, uint v)
{
bw.Write((byte)(v & 0xff));
bw.Write((byte)((v >> 8) & 0xff));
bw.Write((byte)((v >> 16) & 0xff));
bw.Write((byte)((v >> 24) & 0xff));
}
示例2: writeBinary
public void writeBinary()
{
string nom = tbName.Text + ".bytes"; byte i;
BinaryReader br = null;
BinaryWriter bw = null;
FileStream fs = null;
//Ecriture d'octets dans le fichier
bw = new BinaryWriter(File.Create(nom));
i = Convert.ToByte(width.Text);
bw.Write(i);
i = Convert.ToByte(height.Text);
bw.Write(i);
i = Convert.ToByte(random.Checked);
bw.Write(i);
for (int j = 3; j < Convert.ToInt32(width.Text); j++)
{
bw.Write(Convert.ToSByte(0));
}
foreach (DataGridViewRow data in dataGridView1.Rows)
{
for(int j = 0; j < dataGridView1.Columns.Count;j++)
{
i = Convert.ToByte(data.Cells[j].Value);
bw.Write(i);
}
}
bw.Close();
}
示例3: DiscordAudioPacket
public DiscordAudioPacket(char seq, int timestamp, int ssrc, byte[] encodedaudio)
{
this.seq = seq;
this.timestamp = timestamp;
this.ssrc = ssrc;
this.encodedAudio = encodedaudio;
byte[] fullPacket = new byte[RTP_HEADER_BYTE_LENGTH + encodedAudio.Length];
using (MemoryStream ms = new MemoryStream(fullPacket))
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.BaseStream.Position = RTP_VERSION_PAD_EXTEND_INDEX;
writer.Write(RTP_VERSION_PAD_EXTEND);
writer.BaseStream.Position = RTP_PAYLOAD_INDEX;
writer.Write(RTP_PAYLOAD_TYPE);
writer.BaseStream.Position = SEQ_INDEX;
writer.Write(seq);
writer.BaseStream.Position = TIMESTAMP_INDEX;
writer.Write(timestamp);
writer.BaseStream.Position = SSRC_INDEX;
writer.Write(ssrc);
writer.BaseStream.Position = RTP_HEADER_BYTE_LENGTH;
writer.Write(fullPacket);
}
}
}
示例4: RecordData
/// <summary>
/// Write the data of each frame in the file.
/// </summary>
/// <param name="controller">Controller that represent the device.</param>
/// <param name="path">Path of the file where the data will be write.<br/>
/// If one already exist it will be deleted and a new empty on is created.</param>
public void RecordData(Controller controller, String path)
{
if (Directory.Exists(path) == true)
{
String destination = path + "leapMotion.data";
try
{
if (File.Exists(destination) == true)
File.Delete(destination);
file = File.Create(destination);
}
catch (ArgumentException e)
{
throw e;
}
}
else
throw new System.ArgumentException("Destination path doesn't exist", "path");
BinaryWriter writer = new BinaryWriter(file);
for (int f = 9; f >= 0; f--)
{
Frame frameToSerialize = controller.Frame(f);
byte[] serialized = frameToSerialize.Serialize;
Int32 length = serialized.Length;
writer.Write(length);
writer.Write(serialized);
}
}
示例5: Main
static void Main(string[] args)
{
FileStream filStream;
BinaryWriter binWriter;
Console.Write("Enter name of the file: ");
string fileName = Console.ReadLine();
if (File.Exists(fileName))
{
Console.WriteLine("File - {0} already exists!", fileName);
}
else
{
filStream = new FileStream(fileName, FileMode.CreateNew);
binWriter = new BinaryWriter(filStream);
decimal aValue = 2.16M;
binWriter.Write("Sample Run");
for (int i = 0; i < 11; i++)
{
binWriter.Write(i);
}
binWriter.Write(aValue);
binWriter.Close();
filStream.Close();
Console.WriteLine("File Created successfully");
}
Console.ReadKey();
}
示例6: Prepare
/// <summary>
/// Notifies an enlisted object that a transaction is being prepared for commitment.
/// </summary>
/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
public void Prepare(PreparingEnlistment preparingEnlistment)
{
onTxComplete();
try
{
using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
{
var name = TransactionRecoveryInformationFileName;
using (var file = machineStoreForApplication.CreateFile(name + ".temp"))
using(var writer = new BinaryWriter(file))
{
writer.Write(session.ResourceManagerId.ToString());
writer.Write(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction).ToString());
writer.Write(session.DatabaseName ?? "");
writer.Write(preparingEnlistment.RecoveryInformation());
file.Flush(true);
}
machineStoreForApplication.MoveFile(name + ".temp", name);
}
}
catch (Exception e)
{
logger.ErrorException("Could not prepare distributed transaction", e);
preparingEnlistment.ForceRollback(e);
return;
}
preparingEnlistment.Prepared();
}
示例7: GetBytesFromStruct
internal static byte[] GetBytesFromStruct(HeaderMsg header)
{
//byte[] arr = null;
//try
//{
// int size = Marshal.SizeOf(header);
// arr = new byte[size];
// IntPtr ptr = Marshal.AllocHGlobal(size);
// Marshal.StructureToPtr(header, ptr, true);
// Marshal.Copy(ptr, arr, 0, size);
// Marshal.FreeHGlobal(ptr);
//}
//catch(Exception e)
//{
// Console.WriteLine(e.Message);
//}
//return arr;
var stream = new MemoryStream();
var writer = new BinaryWriter(stream);
writer.Write(header.messageID);
writer.Write(header.messageFrom);
writer.Write(header.messageTO);
writer.Write(header.messageSize);
return stream.ToArray();
}
示例8: Initialize
/// <summary>
/// Start a new command of a speicifc type with a global and/or local buffer on the EV3 brick
/// </summary>
/// <param name="commandType">The type of the command to start</param>
/// <param name="globalSize">The size of the global buffer in bytes (maximum of 1024 bytes)</param>
/// <param name="localSize">The size of the local buffer in bytes (maximum of 64 bytes)</param>
public void Initialize(CommandType commandType, ushort globalSize, int localSize)
{
if(globalSize > 1024)
throw new ArgumentException("Global buffer must be less than 1024 bytes", "globalSize");
if(localSize > 64)
throw new ArgumentException("Local buffer must be less than 64 bytes", "localSize");
_stream = new MemoryStream();
_writer = new BinaryWriter(_stream);
Response = ResponseManager.CreateResponse();
CommandType = commandType;
// 2 bytes (this gets filled in later when the user calls ToBytes())
_writer.Write((ushort)0xffff);
// 2 bytes
_writer.Write(Response.Sequence);
// 1 byte
_writer.Write((byte)commandType);
if(commandType == CommandType.DirectReply || commandType == CommandType.DirectNoReply)
{
// 2 bytes (llllllgg gggggggg)
_writer.Write((byte)globalSize); // lower bits of globalSize
_writer.Write((byte)((localSize << 2) | (globalSize >> 8) & 0x03)); // upper bits of globalSize + localSize
}
}
示例9: Save
public override void Save(BinaryWriter outStream)
{
outStream.Write(Id);
outStream.Write(Unknown0);
outStream.Write(Text);
outStream.Write(AudioPath);
}
示例10: WriteVec3
public static void WriteVec3(Vector3 v, BinaryWriter bw)
{
bw.Write(v.X);
bw.Write(v.Y);
bw.Write(v.Z);
bw.Flush();
}
示例11: CallMethodRef
public void CallMethodRef ()
{
var expected = "value";
var moduleBuilder = CreateModuleBuilder ();
var typeBuilder = moduleBuilder.DefineType ("NewType");
var methodBuilder1 = typeBuilder.DefineMethod ("NewMethod1",
MethodAttributes.Public | MethodAttributes.Static,
typeof (string),
Type.EmptyTypes);
var gen1 = methodBuilder1.GetILGenerator ();
gen1.Emit (OpCodes.Ldstr, expected);
gen1.Emit (OpCodes.Ret);
var methodBuilder2 = typeBuilder.DefineMethod ("NewMethod2",
MethodAttributes.Public | MethodAttributes.Static,
typeof (string),
Type.EmptyTypes);
var ilStream = new MemoryStream ();
var ilWriter = new BinaryWriter (ilStream);
ilWriter.Write ((byte) 0x28); // call
ilWriter.Write ((int) moduleBuilder.GetMethodToken (methodBuilder1).Token);
ilWriter.Write ((byte) 0x2A); // ret
SetIL (methodBuilder2, ilStream);
var type = typeBuilder.CreateType ();
Assert.AreEqual (expected, Invoke (type, methodBuilder2));
}
示例12: Write
/// <summary>
/// Writes the event data to the underlying stream.
/// </summary>
/// <param name="writer">The writer.</param>
public override void Write(BinaryWriter writer)
{
base.Write(writer);
writer.Write(Colour.Minimum);
writer.Write(Colour.Maximum);
}
示例13: WriteDataTo
public void WriteDataTo(BinaryWriter writer)
{
writer.Write(File == null ? "" : File);
writer.Write((int) LineNumber);
writer.Write((int) LinePosition);
writer.Write(ErrorMessage == null ? "" : ErrorMessage);
}
示例14: SerializeInto
public override void SerializeInto(BinaryWriter writer)
{
base.SerializeInto(writer);
writer.Write(Interaction);
writer.Write(CalleeID);
writer.Write(Param0);
}
示例15: SerializeBody
public override void SerializeBody(BinaryWriter bw)
{
bw.Write(Constructor);
ObjectUtils.SerializeObject(webpage,bw);
bw.Write(pts);
bw.Write(pts_count);
}