本文整理汇总了C#中BinaryWriter类的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter类的具体用法?C# BinaryWriter怎么用?C# BinaryWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryWriter类属于命名空间,在下文中一共展示了BinaryWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(BinaryWriter Stream)
{
Stream.Write(PathTexture, true);
Stream.Write(PathNormalmap, true);
Stream.Write(ScaleTexture);
Stream.Write(ScaleNormalmap);
}
示例2: GameLogger
public GameLogger()
{
DateTime now = DateTime.Now;
string dir = "";
if(Application.platform == RuntimePlatform.Android)
{
dir = Application.persistentDataPath + "/logs/";
}
else if(Application.platform == RuntimePlatform.IPhonePlayer)
{
dir = Application.persistentDataPath + "/logs/";
}
else if(Application.platform == RuntimePlatform.WindowsPlayer)
{
dir = Application.dataPath + "/logs/";
}
else
return;
if(!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
this.mFile = new FileStream(dir + "log_" + now.ToString("MM-dd_hh-mm-ss") + ".log",FileMode.Append);
this.mFileWriter = new BinaryWriter(this.mFile);
}
示例3: Main
public static int Main () {
MemoryStream mr = new MemoryStream();
BinaryWriter wr = new BinaryWriter(mr);
wr.Write ((byte) 1);
wr.Write ((int) 1);
wr.Write ((int) -1);
byte [] arr = mr.ToArray();
Console.Write ("Array (should be: 1 1 0 0 0 ff ff ff ff): ");
for (int a = 0; a != arr.Length; a++)
Console.Write(arr[a].ToString("x") + " ");
Console.WriteLine();
if (arr.Length != 9)
return 4;
if (arr[0] != 1)
return 1;
if (arr[1] != 1 && arr[2] != 0 && arr[3] != 0 && arr[4] != 0)
return 2;
if (arr[5] != 0xff && arr[6] != 0xff && arr[7] != 0xff && arr[8] != 0xff)
return 3;
Console.WriteLine("test-ok");
return 0;
}
示例4: WriteData
public void WriteData(BinaryWriter resourceWriter)
{
if (fileReference == null)
{
try
{
using (Stream stream = streamProvider())
{
if (stream == null)
{
throw new InvalidOperationException(CodeAnalysisResources.ResourceStreamProviderShouldReturnNonNullStream);
}
var count = (int)(stream.Length - stream.Position);
resourceWriter.WriteInt(count);
var to = resourceWriter.BaseStream;
var position = (int)to.Position;
to.Position = (uint)(position + count);
resourceWriter.Align(8);
var buffer = to.Buffer;
stream.Read(buffer, position, count);
}
}
catch (Exception e)
{
throw new ResourceException(this.name, e);
}
}
}
示例5: Write
public void Write(BinaryWriter w)
{
//if (w == null) throw new ArgumentNullException("w");
w.Write(FResult.ToString());
w.Write(FSeparator);
w.Write(FEmpty);
}
示例6: Save
public override void Save(BinaryWriter bw) {
base.Save(bw);
bw.Write(dir == 1);
bw.Write((byte)height);
bw.Write(sin);
bw.Write(sinSpeed);
}
示例7: SaveGame
public static bool SaveGame()
{
GameDataContainer data = new GameDataContainer ();
data.Money = GameController.Instance.Money;
for(int i = 0; i < (int)Products.Max; i++) {
data.ProdList[i] = GameController.Instance.ProdList[(Products)i].Level;
}
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite("Data/SaveGame.dat")))
{
bw.Write(new char[10]);
byte[] money = Encoding.ASCII.GetBytes(data.Money.ToString());
bw.Write(money.Length);
bw.Write(money);
for (int i = 0; i < (int)Products.Max; i++) {
bw.Write(data.ProdList[i]);
}
int upCount = UpgradeController.Instance.AcquiredUps.Count;
bw.Write(upCount);
for(int i = 0; i < upCount; i++) {
bw.Write(UpgradeController.Instance.AcquiredUps[i]);
}
}
return true;
}
示例8: Serialize
public static byte[] Serialize(Account account)
{
using (MemoryStream stream = new MemoryStream())
using (BinaryWriter writer = new BinaryWriter(stream))
{
try
{
writer.Write(account.Email);
writer.Write(account.Username);
writer.Write((byte)account.Characters.Length);
for (int i = 0; i < account.Characters.Length; i++)
{
byte[] bytes = Serialize(account.Characters[i]);
writer.Write(bytes.Length);
writer.Write(bytes);
}
return stream.ToArray();
}
catch (Exception e)
{
Debug.Log("Exception at Serialization.Serialize: " + e.Message);
return new byte[0];
}
}
}
示例9: RpcTellClientTime
public void RpcTellClientTime(int current_count)
{
current_count = 60 * 5 - current_count;
int min = current_count / 60;
int sec = current_count % 60;
int ten_sec = sec / 10;
int one_sec = sec % 10;
score_.text = "ClearTime:" + min.ToString() + ":" + ten_sec.ToString() + one_sec.ToString();
score_.gameObject.SetActive(true);
hi_score_text_.gameObject.SetActive(true);
if (current_count > hi_score_) return;
if (is_director_) return;
is_director_ = true;
{
var path = Application.dataPath + "/" + "ranki.txt";
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
if (writer != null)
{
writer.Write(current_count);
writer.Close();
}
}
StartCoroutine(ChangeColor());
}
示例10: ExtractFile
public static void ExtractFile(ListViewFileItem lvi, string exeName, string outName)
{
//extract file in ListViewFileItem
FileStream fsIn = null;
BinaryReader brIn = null;
FileStream fsOut = null;
BinaryWriter bwOut = null;
try
{
fsIn = new FileStream(exeName, FileMode.Open);
brIn = new BinaryReader(fsIn);
fsOut = new FileStream(outName, FileMode.Create);
bwOut = new BinaryWriter(fsOut);
fsIn.Seek(lvi.Offset, SeekOrigin.Begin);
bwOut.Write(brIn.ReadBytes(lvi.Size));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (brIn != null)
brIn.Close();
if (fsIn != null)
fsIn.Close();
if (bwOut != null)
bwOut.Close();
if (fsOut != null)
fsOut.Close();
}
}
示例11: SaveToDisk
public static void SaveToDisk(string resourceName, string fileName)
{
// Get a reference to the running application.
Assembly assy = Assembly.GetExecutingAssembly();
// Loop through each resource, looking for the image name (case-insensitive).
foreach (string resource in assy.GetManifestResourceNames()) {
if (resource.ToLower().IndexOf(resourceName.ToLower()) != -1) {
// Get the embedded file from the assembly as a MemoryStream.
using (System.IO.Stream resourceStream = assy.GetManifestResourceStream(resource)) {
if (resourceStream != null) {
using (BinaryReader reader = new BinaryReader(resourceStream)) {
// Read the bytes from the input stream.
byte[] buffer = reader.ReadBytes(Convert.ToInt32(resourceStream.Length));
using (FileStream outputStream = new FileStream(fileName, FileMode.Create)) {
using (BinaryWriter writer = new BinaryWriter(outputStream)) {
// Write the bytes to the output stream.
writer.Write(buffer);
}
}
}
}
}
break; // TODO: might not be correct. Was : Exit For
}
}
}
示例12: ReadBlob
// read the BLOB into file "cs-parser2.cs"
public static void ReadBlob (OracleConnection connection)
{
if (File.Exists(outfilename) == true) {
Console.WriteLine("Filename already exists: " + outfilename);
return;
}
OracleCommand rcmd = connection.CreateCommand ();
rcmd.CommandText = "SELECT BLOB_COLUMN FROM BLOBTEST";
OracleDataReader reader2 = rcmd.ExecuteReader ();
if (!reader2.Read ())
Console.WriteLine ("ERROR: RECORD NOT FOUND");
Console.WriteLine (" TESTING OracleLob OBJECT 2...");
OracleLob lob2 = reader2.GetOracleLob (0);
Console.WriteLine (" LENGTH: {0}", lob2.Length);
Console.WriteLine (" CHUNK SIZE: {0}", lob2.ChunkSize);
byte[] lobvalue = (byte[]) lob2.Value;
if (ByteArrayCompare(bytes1, lobvalue) == true)
Console.WriteLine("bytes1 and bytes2 are equal: good");
else
Console.WriteLine("bytes1 and bytes2 are not equal: bad");
FileStream fs = new FileStream(outfilename, FileMode.CreateNew);
BinaryWriter w = new BinaryWriter(fs);
w.Write(lobvalue);
w.Close();
fs.Close();
lob2.Close ();
reader2.Close ();
}
示例13: ExecuteSaveFontTexture
public static void ExecuteSaveFontTexture()
{
Texture2D tex = Selection.activeObject as Texture2D;
if (tex == null)
{
EditorUtility.DisplayDialog("No texture selected", "Please select a texture", "Cancel");
return;
}
if (tex.format != TextureFormat.Alpha8)
{
EditorUtility.DisplayDialog("Wrong format", "Texture must be in uncompressed Alpha8 format", "Cancel");
return;
}
// Convert Alpha8 texture to ARGB32 texture so it can be saved as a PNG
var texPixels = tex.GetPixels();
var tex2 = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
tex2.SetPixels(texPixels);
// Save texture (WriteAllBytes is not used here in order to keep compatibility with Unity iPhone)
var texBytes = tex2.EncodeToPNG();
var fileName = EditorUtility.SaveFilePanel("Save font texture", "", "font Texture", "png");
if (fileName.Length > 0)
{
FileStream f = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter b = new BinaryWriter(f);
for (var i = 0; i < texBytes.Length; i++) b.Write(texBytes[i]);
b.Close();
}
GameObject.DestroyImmediate(tex2);
}
示例14: Update
// Update is called once per frame
void Update () {
if (OpenFileChoose)
{
FolderPath = EditorUtility.SaveFolderPanel("フォルダ選択", " ", " ");
OpenFileChoose = false;
}
if (FolderPath != null)
{
if (Savestart)
{
this.writer = new BinaryWriter(File.OpenWrite(FolderPath + @"\" + filename));
thread = new Thread(new ThreadStart(Save));
thread.Start();
Savestart = false;
}
}
}
示例15: Load
public void Load(int Index){
MemoryMappedFileSecurity CustomSecurity = new MemoryMappedFileSecurity();
CustomSecurity.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType
.Allow));
using(MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("bits", (long)Math.Ceiling(Length/8.0), MemoryMappedFileAccess.ReadWriteExecute, MemoryMappedFileOptions.None, CustomSecurity, System.IO.HandleInheritability.Inheritable)){
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
int Amount = (int)Math.Ceiling((double)(Length/Int32.MaxValue));
int Remainder = (int)(Length%Int32.MaxValue);
int length = (int)(Amount==Index?Math.Ceiling(Remainder/8.0):Math.Ceiling(Int32.MaxValue/8.0));
byte[] buffer = BitArrayToByteArray(LoadedArray,0,LoadedArray.Length);
stream.Position=(long)Math.Ceiling((Int32.MaxValue/8.0))*LoadedArrayIndex;
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(buffer);
stream.Position=0;//(long)Math.Ceiling((Int32.MaxValue/8.0))*Index;
BinaryReader reader = new BinaryReader(stream);
buffer = new byte[(int)Math.Ceiling((Int32.MaxValue/8.0))];
try{reader.Read(buffer,(int)Math.Ceiling((Int32.MaxValue/8.0))*Index,(int)Math.Ceiling((Int32.MaxValue/8.0)));} catch{LoadedArray = new BitArray((int)(length*8.0));}
}
}
//int ElementIndex = (int)Math.Floor((double)(T/Int32.MaxValue));
//int Index = (int)(T%Int32.MaxValue);
//Elements[ElementIndex][Index]=value;
//}
}