本文整理汇总了C#中System.IO.BinaryWriter类的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryWriter类的具体用法?C# System.IO.BinaryWriter怎么用?C# System.IO.BinaryWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
System.IO.BinaryWriter类属于命名空间,在下文中一共展示了System.IO.BinaryWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reset
public void Reset()
{
var messageStream = new System.IO.MemoryStream();
var messageWriter = new System.IO.BinaryWriter(messageStream);
messageWriter.Write(1);
SendMessage(messageStream.ToArray());
}
示例2: CreateSelfSignCertificate
static void CreateSelfSignCertificate(CertOption option)
{
var fileName = option.CertFileName;
var subject = option.Subject;
var password = option.Password;
try
{
var securePassword = Certificate.ConvertSecureString(password);
var startDate = DateTime.Now;
var endDate = startDate.AddYears(option.Years);
var certData = Certificate.CreateSelfSignCertificatePfx(subject, startDate, endDate, securePassword);
using (var writer = new System.IO.BinaryWriter(System.IO.File.Open(fileName, System.IO.FileMode.Create)))
{
writer.Write(certData);
writer.Flush();
writer.Close();
}
securePassword = Certificate.ConvertSecureString(password);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例3: Assemble
public static void Assemble(string infile, string outfile, string origin)
{
CurrentNdx = 0;
AsLength = Convert.ToUInt16(origin, 16);
IsEnd = false;
ExecutionAddress = 0;
LabelTable = new System.Collections.Hashtable(50);
System.IO.BinaryWriter output;
System.IO.TextReader input;
System.IO.FileStream fs = new System.IO.FileStream(outfile, System.IO.FileMode.Create);
output = new System.IO.BinaryWriter(fs);
input = System.IO.File.OpenText(infile);
SourceProgram = input.ReadToEnd();
input.Close();
output.Write('B');
output.Write('3');
output.Write('2');
output.Write(Convert.ToUInt16(origin, 16));
output.Write((ushort)0);
Parse(output, origin);
output.Seek(5, System.IO.SeekOrigin.Begin);
output.Write(ExecutionAddress);
output.Close();
fs.Close();
}
示例4: FormaterBuffer
public FormaterBuffer(int size)
{
mBuffer = new byte[size];
mStream = new System.IO.MemoryStream(mBuffer);
mReader = new System.IO.BinaryReader(mStream);
mWriter = new System.IO.BinaryWriter(mStream);
}
示例5: packMe
public override byte[] packMe()
{
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(new System.IO.MemoryStream());
writer.Write(frompos);
writer.Write(topos);
return ((System.IO.MemoryStream)writer.BaseStream).GetBuffer();
}
示例6: BaseField_Leave
public override void BaseField_Leave(object sender, EventArgs e)
{
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(meta.MS);
if (((WinMetaEditor)this.ParentForm).checkSelectionInCurrentTag())
bw.BaseStream.Position = this.offsetInMap - meta.offset;
try
{
this.value = int.Parse(this.comboBox1.Text);
}
catch
{
this.value = this.comboBox1.SelectedIndex;
}
switch (this.enumType)
{
case 8:
{
bw.Write(Convert.ToByte(this.value));
break;
}
case 16:
{
bw.Write(Convert.ToInt16(this.value));
break;
}
case 32:
{
bw.Write(this.value);
break;
}
}
}
示例7: packMe
public override byte[] packMe()
{
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(new System.IO.MemoryStream());
writer.Write(message);
writer.Write(bounced);
return ((System.IO.MemoryStream)writer.BaseStream).GetBuffer();
}
示例8: SerializeVoxelAreaData
public static byte[] SerializeVoxelAreaData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write (v.width);
writer.Write (v.depth);
writer.Write (v.linkedSpans.Length);
for (int i=0;i<v.linkedSpans.Length;i++) {
writer.Write(v.linkedSpans[i].area);
writer.Write(v.linkedSpans[i].bottom);
writer.Write(v.linkedSpans[i].next);
writer.Write(v.linkedSpans[i].top);
}
//writer.Close();
writer.Flush();
Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
stream.Position = 0;
zip.AddEntry ("data",stream);
System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
zip.Save(stream2);
byte[] bytes = stream2.ToArray();
stream.Close();
stream2.Close();
return bytes;
#else
throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
}
示例9: split
public static void split(string input_path, string dir_path, int nb)
{
System.IO.FileStream inf = new System.IO.FileStream(input_path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader reader = new System.IO.BinaryReader(inf);
System.IO.BinaryWriter[] writers = new System.IO.BinaryWriter[nb];
for (int x = 0; x < nb; x++)
{
writers[x] = new System.IO.BinaryWriter(new System.IO.FileStream(dir_path + "/part_" + (x + 1) + ".ACDC",
System.IO.FileMode.Create,
System.IO.FileAccess.Write));
}
int i = 0;
while (reader.PeekChar() != -1)
{
writers[i % nb].Write(reader.ReadChar());
i++;
}
for (int j=0; j<nb; j++)
{
writers[j].Close();
}
}
示例10: PNGtoBIN
public static void PNGtoBIN(string path_in, string path_out, string[] param = null)
{
Image png = Image.FromFile(path_in);
Bitmap bmp = new Bitmap(png);
if ((png.Width != 128) && (png.Height != 32))
return;
int tiles_w = png.Width / 4;
int tiles_h = png.Height / 8;
ushort[] binary = new ushort[256];
for (int y = 0; y < tiles_h; y++)
{
for (int x = 0; x < tiles_w; x++)
{
ushort[] tile = new ushort[2];
for (int iY = 0; iY < 8; iY++)
{
for (int iX = 0; iX < 4; iX++)
{
Color color = bmp.GetPixel(x * 4 + iX, y * 8 + iY);
if (color.R + color.G + color.B > 0x0100)
tile[(iY / 4)] |= (ushort)(1 << ((iY % 4) * 4 + iX));
}
}
binary[y * tiles_w * 2 + x * 2 + 0] = tile[0];
binary[y * tiles_w * 2 + x * 2 + 1] = tile[1];
}
}
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Open(path_out, System.IO.FileMode.Create));
for (int i = 0; i < 256; i++)
writer.Write(binary[i]);
writer.Close();
}
示例11: BaseField_Leave
public override void BaseField_Leave(object sender, EventArgs e)
{
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(meta.MS);
if (((WinMetaEditor)this.ParentForm).checkSelectionInCurrentTag())
bw.BaseStream.Position = this.offsetInMap - meta.offset;
bw.Write((short)this.sidIndexer);
bw.Write((byte) 0);
bw.Write((byte)map.Strings.Length[this.sidIndexer]);
/*
// Check for typed value
SID sid = (SID)(sender);
if (sid.comboBox1.Text != map.Strings.Name[sid.sidIndexer])
{
for (int i = 0; i < map.Strings.Name.Length; i++)
if (map.Strings.Name[i].ToLower() == sid.comboBox1.Text.ToLower())
{
sid.sidIndexer = i;
break;
}
sid.comboBox1.Text = map.Strings.Name[sid.sidIndexer];
}
*/
//if (this.AutoSave)
// this.Save();
}
示例12: getPdfFile
public void getPdfFile(string fileName)
{
using (SqlConnection cn = new SqlConnection(ConnectionString))
{
cn.Open();
using (SqlCommand cmd = new SqlCommand($"select FileSource from PdfDocumentFiles where Name='{fileName}' ", cn))
{
using (SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.Default))
{
if (dr.Read())
{
byte[] fileData = (byte[])dr.GetValue(0);
using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
{
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
{
bw.Write(fileData);
bw.Close();
}
}
}
dr.Close();
}
}
}
}
示例13: SerializeVoxelAreaCompactData
public static byte[] SerializeVoxelAreaCompactData (VoxelArea v) {
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write (v.width);
writer.Write (v.depth);
writer.Write (v.compactCells.Length);
writer.Write(v.compactSpans.Length);
writer.Write(v.areaTypes.Length);
for (int i=0;i<v.compactCells.Length;i++) {
writer.Write(v.compactCells[i].index);
writer.Write(v.compactCells[i].count);
}
for (int i=0;i<v.compactSpans.Length;i++) {
writer.Write(v.compactSpans[i].con);
writer.Write(v.compactSpans[i].h);
writer.Write(v.compactSpans[i].reg);
writer.Write(v.compactSpans[i].y);
}
for (int i=0;i<v.areaTypes.Length;i++) {
//TODO: RLE encoding
writer.Write(v.areaTypes[i]);
}
writer.Close();
return stream.ToArray();
}
示例14: SerializeVoxelAreaData
public static byte[] SerializeVoxelAreaData (VoxelArea v) {
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write (v.width);
writer.Write (v.depth);
writer.Write (v.linkedSpans.Length);
for (int i=0;i<v.linkedSpans.Length;i++) {
writer.Write(v.linkedSpans[i].area);
writer.Write(v.linkedSpans[i].bottom);
writer.Write(v.linkedSpans[i].next);
writer.Write(v.linkedSpans[i].top);
}
//writer.Close();
writer.Flush();
Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
stream.Position = 0;
zip.AddEntry ("data",stream);
System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
zip.Save(stream2);
byte[] bytes = stream2.ToArray();
stream.Close();
stream2.Close();
return bytes;
}
示例15: SerializeVoxelAreaCompactData
public static byte[] SerializeVoxelAreaCompactData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write (v.width);
writer.Write (v.depth);
writer.Write (v.compactCells.Length);
writer.Write(v.compactSpans.Length);
writer.Write(v.areaTypes.Length);
for (int i=0;i<v.compactCells.Length;i++) {
writer.Write(v.compactCells[i].index);
writer.Write(v.compactCells[i].count);
}
for (int i=0;i<v.compactSpans.Length;i++) {
writer.Write(v.compactSpans[i].con);
writer.Write(v.compactSpans[i].h);
writer.Write(v.compactSpans[i].reg);
writer.Write(v.compactSpans[i].y);
}
for (int i=0;i<v.areaTypes.Length;i++) {
//TODO: RLE encoding
writer.Write(v.areaTypes[i]);
}
writer.Close();
return stream.ToArray();
#else
throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
}