本文整理汇总了C#中System.IO.BinaryWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryWriter.Flush方法的具体用法?C# System.IO.BinaryWriter.Flush怎么用?C# System.IO.BinaryWriter.Flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了System.IO.BinaryWriter.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRaw
static void TestRaw()
{
using (var vorbis = new NVorbis.VorbisReader(@"..\..\..\TestFiles\2test.ogg"))
using (var outFile = System.IO.File.Create(@"..\..\..\TestFiles\2test.wav"))
using (var writer = new System.IO.BinaryWriter(outFile))
{
writer.Write(Encoding.ASCII.GetBytes("RIFF"));
writer.Write(0);
writer.Write(Encoding.ASCII.GetBytes("WAVE"));
writer.Write(Encoding.ASCII.GetBytes("fmt "));
writer.Write(18);
writer.Write((short)1); // PCM format
writer.Write((short)vorbis.Channels);
writer.Write(vorbis.SampleRate);
writer.Write(vorbis.SampleRate * vorbis.Channels * 2); // avg bytes per second
writer.Write((short)(2 * vorbis.Channels)); // block align
writer.Write((short)16); // bits per sample
writer.Write((short)0); // extra size
writer.Write(Encoding.ASCII.GetBytes("data"));
writer.Flush();
var dataPos = outFile.Position;
writer.Write(0);
var buf = new float[vorbis.SampleRate / 10 * vorbis.Channels];
int count;
while ((count = vorbis.ReadSamples(buf, 0, buf.Length)) > 0)
{
for (int i = 0; i < count; i++)
{
var temp = (int)(32767f * buf[i]);
if (temp > 32767)
{
temp = 32767;
}
else if (temp < -32768)
{
temp = -32768;
}
writer.Write((short)temp);
}
}
writer.Flush();
writer.Seek(4, System.IO.SeekOrigin.Begin);
writer.Write((int)(outFile.Length - 8L));
writer.Seek((int)dataPos, System.IO.SeekOrigin.Begin);
writer.Write((int)(outFile.Length - dataPos - 4L));
writer.Flush();
}
}
示例2: 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;
}
示例3: 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
}
示例4: 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);
}
}
示例5: Save
public static void Save(string directory, string file,string ext, XCImageCollection images)
{
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(directory+"\\"+file+ext));
foreach(XCImage tile in images)
bw.Write(tile.Bytes);
bw.Flush();
bw.Close();
}
示例6: WriteZippedResources
public void WriteZippedResources()
{
using (var binWriter = new System.IO.BinaryWriter(this.fileSystem.File.OpenWrite(MyDhtmlResourceSet.ZippedResources.LocalPath)))
{
binWriter.Write(Properties.Resources.Pickles_BaseDhtmlFiles);
binWriter.Flush();
binWriter.Close();
}
}
示例7: SaveToFile
public void SaveToFile(string fileName)
{
using(var writer = new System.IO.BinaryWriter(System.IO.File.OpenWrite(fileName)))
{
writer.Write(_header);
writer.Write(_bytes);
writer.Flush();
}
}
示例8: Main
static void Main(string[] args)
{
var options = new SwitchOptions();
if (!CommandLine.ParseArguments(args, options))
return;
try
{
if (String.IsNullOrEmpty(options.outFile))
{
Console.WriteLine("You must supply an outfile.");
return;
}
var source = new System.IO.StreamReader(options.inFile);
var lexed = new LexResult();
var r = Lexer.Lex(source, lexed);
if (r == 0x00)
{
var destination = System.IO.File.Open(options.outFile, System.IO.FileMode.Create);
var writer = new System.IO.BinaryWriter(destination);
r = Assembler.Assemble(lexed, writer);
writer.Flush();
destination.Flush();
writer.Close();
}
Console.WriteLine("Finished with code " + r);
}
/*case "emulate":
{
var source = System.IO.File.Open(options.inFile, System.IO.FileMode.Open);
var emulator = new IN8();
source.Read(emulator.MEM, 0, 0xFFFF);
// Attach devices
var teletypeTerminal = new TT3();
emulator.AttachHardware(teletypeTerminal, 0x04);
while (emulator.STATE_FLAGS == 0x00) emulator.Step();
Console.WriteLine(String.Format("Finished in state {0:X2}", emulator.STATE_FLAGS));
Console.WriteLine(String.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2}",
emulator.A, emulator.B, emulator.C, emulator.D, emulator.E, emulator.H, emulator.L, emulator.O));
Console.WriteLine(String.Format("{0:X4} {1:X4} {2:X8}", emulator.IP, emulator.SP, emulator.CLOCK));
break;
}
}
}*/
catch (Exception e)
{
Console.WriteLine("An error occured.");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
示例9: GetCollisionShape
public override CollisionShape GetCollisionShape()
{
if (collisionShapePtr == null) {
Terrain t = GetComponent<Terrain>();
if (t == null)
{
Debug.LogError("Needs to be attached to a game object with a Terrain component." + name);
return null;
}
BTerrainCollisionObject tco = GetComponent<BTerrainCollisionObject>();
if (tco == null)
{
Debug.LogError("Needs to be attached to a game object with a BTerrainCollisionObject." + name);
}
TerrainData td = t.terrainData;
int width = td.heightmapWidth;
int length = td.heightmapHeight;
float maxHeight = td.size.y;
//generate procedural data
byte[] terr = new byte[width * length * sizeof(float)];
System.IO.MemoryStream file = new System.IO.MemoryStream(terr);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(file);
for (int i = 0; i < length; i++)
{
float[,] row = td.GetHeights(0, i, width, 1);
for (int j = 0; j < width; j++)
{
writer.Write((float)row[0, j] * maxHeight);
}
}
writer.Flush();
file.Position = 0;
pinnedTerrainData = GCHandle.Alloc(terr,GCHandleType.Pinned);
collisionShapePtr = new HeightfieldTerrainShape(width, length, pinnedTerrainData.AddrOfPinnedObject(), 1f, 0f, maxHeight, upIndex, scalarType, false);
((HeightfieldTerrainShape)collisionShapePtr).SetUseDiamondSubdivision(true);
((HeightfieldTerrainShape)collisionShapePtr).LocalScaling = new BulletSharp.Math.Vector3(td.heightmapScale.x, 1f, td.heightmapScale.z);
//just allocated several hundred float arrays. Garbage collect now since 99% likely we just loaded the scene
GC.Collect();
}
return collisionShapePtr;
}
示例10: WriteToSocket
private void WriteToSocket(byte[] buffer)
{
try
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(ns);
sw.WriteLine(buffer.Length.ToString());
sw.Flush();
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ns);
System.Console.WriteLine("size of array: " + buffer.Length);
bw.Write(buffer);
bw.Flush();
}
catch (Exception)
{
Idp.DataChanged -= Idp_DataChanged;
ns.Close();
SocketForClient.Close();
}
}
示例11: SaveStateBinary
public byte[] SaveStateBinary()
{
var ms = new System.IO.MemoryStream(savebuff2, true);
var bw = new System.IO.BinaryWriter(ms);
SaveStateBinary(bw);
bw.Flush();
ms.Close();
return savebuff2;
}
示例12: DecryptFile
/// <summary>
/// Descriptografa um arquivo em outro arquivo.
/// </summary>
/// <param name="p_inputfilename">Nome do arquivo de entrada.</param>
/// <param name="p_outputfilename">Nome do arquivo de saída.</param>
public void DecryptFile(string p_inputfilename, string p_outputfilename)
{
System.IO.FileStream v_inputfile, v_outputfile;
System.IO.StreamReader v_reader;
System.IO.BinaryWriter v_writer;
int v_bytestoread;
string v_chunk;
byte[] v_decryptedchunk;
try
{
v_inputfile = new System.IO.FileStream(p_inputfilename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
v_outputfile = new System.IO.FileStream(p_outputfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
v_reader = new System.IO.StreamReader(v_inputfile);
v_writer = new System.IO.BinaryWriter(v_outputfile);
v_bytestoread = (int) v_inputfile.Length;
while (! v_reader.EndOfStream)
{
v_chunk = v_reader.ReadLine();
// descriptografando
v_decryptedchunk = this.DecryptToBytes(v_chunk);
// escrevendo porcao descriptografada
v_writer.Write(v_decryptedchunk);
}
v_reader.Close();
v_writer.Flush();
v_writer.Close();
}
catch (System.IO.IOException e)
{
throw new Spartacus.Utils.Exception(e);
}
catch (System.Exception e)
{
throw new Spartacus.Utils.Exception(e);
}
}
示例13: button1_Click
// ***** Start pairing (play sound)*****
private void button1_Click(object sender, EventArgs e)
{
if (clsHvcw.GenerateSound(textSSID.Text, textPassword.Text, txtToken) == true)
{
// Read sound file
byte[] buf = System.IO.File.ReadAllBytes(clsHvcw.SoundFile);
// Stop when sound playing
if (player != null)
StopSound();
player = new System.Media.SoundPlayer();
// Wav header definition
WAVHDR wavHdr = new WAVHDR();
uint fs = 8000;
wavHdr.formatid = 0x0001; // PCM uncompressed
wavHdr.channel = 1; // ch=1 mono
wavHdr.fs = fs; // Frequency
wavHdr.bytespersec = fs * 2; // 16bit
wavHdr.blocksize = 2; // 16bit mono so block size (byte/sample x # of channels) is 2
wavHdr.bitspersample = 16; // bit/sample
wavHdr.size = (uint)buf.Length; // Wave data byte number
wavHdr.fileSize = wavHdr.size + (uint)Marshal.SizeOf(wavHdr); // Total byte number
// Play sound through memory stream
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream((int)wavHdr.fileSize);
System.IO.BinaryWriter bWriter = new System.IO.BinaryWriter(memoryStream);
// Write Wav header
foreach (byte b in wavHdr.getByteArray())
{
bWriter.Write(b);
}
// Write PCM data
foreach (byte data in buf)
{
bWriter.Write(data);
}
bWriter.Flush();
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
player.Stream = memoryStream;
// Async play
player.Play();
// Wait until sound playing is over with following:
// player.PlaySync();
}
else
{
MessageBox.Show("Pairing sound creation failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例14: SaveStateBinary
public byte[] SaveStateBinary()
{
var ms = new System.IO.MemoryStream(SaveStateBuff2, true);
var bw = new System.IO.BinaryWriter(ms);
SaveStateBinary(bw);
bw.Flush();
if (ms.Position != SaveStateBuff2.Length)
throw new InvalidOperationException("Unexpected savestate length!");
bw.Close();
return SaveStateBuff2;
}
示例15: Complete
/// <summary>
/// Emits a return statement and finalizes the generated code. Do not emit any more
/// instructions after calling this method.
/// </summary>
public override unsafe void Complete()
{
// Check there aren't any outstanding exception blocks.
if (this.activeExceptionRegions != null && this.activeExceptionRegions.Count > 0)
throw new InvalidOperationException("The current method contains unclosed exception blocks.");
Return();
FixLabels();
fixed (byte* bytes = this.bytes)
this.dynamicILInfo.SetCode(bytes, this.offset, this.maxStackSize);
this.dynamicILInfo.SetLocalSignature(this.LocalSignature);
if (this.exceptionRegions != null && this.exceptionRegions.Count > 0)
{
// Count the number of exception clauses.
int clauseCount = 0;
foreach (var exceptionRegion in this.exceptionRegions)
clauseCount += exceptionRegion.Clauses.Count;
var exceptionBytes = new byte[4 + 24 * clauseCount];
var writer = new System.IO.BinaryWriter(new System.IO.MemoryStream(exceptionBytes));
// 4-byte header, see Partition II, section 25.4.5.
writer.Write((byte)0x41); // Flags: CorILMethod_Sect_EHTable | CorILMethod_Sect_FatFormat
writer.Write(exceptionBytes.Length); // 3-byte data size.
writer.Flush();
writer.BaseStream.Seek(4, System.IO.SeekOrigin.Begin);
// Exception clauses, see Partition II, section 25.4.6.
foreach (var exceptionRegion in this.exceptionRegions)
{
foreach (var clause in exceptionRegion.Clauses)
{
switch (clause.Type)
{
case ExceptionClauseType.Catch:
writer.Write(0); // Flags
break;
case ExceptionClauseType.Filter:
writer.Write(1); // Flags
break;
case ExceptionClauseType.Finally:
writer.Write(2); // Flags
break;
case ExceptionClauseType.Fault:
writer.Write(4); // Flags
break;
}
writer.Write(exceptionRegion.Start); // TryOffset
writer.Write(clause.ILStart - exceptionRegion.Start); // TryLength
writer.Write(clause.ILStart); // HandlerOffset
writer.Write(clause.ILLength); // HandlerLength
if (clause.Type == ExceptionClauseType.Catch)
writer.Write(clause.CatchToken); // ClassToken
else if (clause.Type == ExceptionClauseType.Filter)
writer.Write(clause.FilterHandlerStart); // FilterOffset
else
writer.Write(0);
}
}
writer.Flush();
this.dynamicILInfo.SetExceptions(exceptionBytes);
}
}