本文整理汇总了C#中BinaryWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.Flush方法的具体用法?C# BinaryWriter.Flush怎么用?C# BinaryWriter.Flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: encode
public byte[] encode(ItemQuote item)
{
MemoryStream mem = new MemoryStream();
BinaryWriter output = new BinaryWriter(new BufferedStream(mem));
output.Write(IPAddress.HostToNetworkOrder(item.itemNumber));
output.Write(IPAddress.HostToNetworkOrder(item.quantity));
output.Write(IPAddress.HostToNetworkOrder(item.unitPrice));
byte flags = 0;
if (item.discounted)
flags |= ItemQuoteBinConst.DISCOUNT_FLAG;
if (item.inStock)
flags |= ItemQuoteBinConst.IN_STOCK_FLAG;
output.Write(flags);
byte[] encodedDesc = encoding.GetBytes(item.itemDescription);
if (encodedDesc.Length > ItemQuoteBinConst.MAX_DESC_LEN)
throw new IOException("Item Description exceeds encoded length limit");
output.Write((byte)encodedDesc.Length);
output.Write(encodedDesc);
output.Flush();
return mem.ToArray();
}
示例2: CreatePhoto
void CreatePhoto()
{
try
{
string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);
string dirUrl = "~/Uploads/cuc_Picture/";
string dirPath = Server.MapPath(dirUrl);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
FileStream fs = new FileStream(dirPath+"St_Pic.jpg", FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs);
br.Write(photo);
br.Flush();
br.Close();
fs.Close();
string camimg = dirPath + "St_Pic.jpg";
Session["imagePath"] = camimg;
}
catch (Exception Ex)
{
}
}
示例3: GetResourcesFrameRender
public static void GetResourcesFrameRender(Dictionary<string, string> taskdetails)
{
FileStream fs;
BinaryWriter bw;
Dictionary<string, string> response = XMLRPC.Instance.getFrameRenderResources(Convert.ToInt32(taskdetails["projid"]));
string resourcefilepath = "resources" + Config.Instance.Slash() + response["filename"];
//Open File for writing
fs = new FileStream(resourcefilepath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
bw.Write(Convert.FromBase64String(response["data"]));
bw.Flush();
bw.Close();
fs.Close();
//Is the file a archive.. then unpack it
if (Path.GetExtension(response["filename"]) == ".zip")
{
Archive oArchive = new Archive(resourcefilepath);
oArchive.Extract("resources");
}
}
示例4: Main
public static void Main() {
byte[] bytes;
var values = new long[] {
0, 1, 0xFFFF, 0xFF00FF00FF00L, 12345678901234L, -0xFFFF, -0xFF00FF00FF00L
};
long length;
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms)) {
foreach (var value in values) {
bw.Write(value);
Console.WriteLine(value);
}
bw.Flush();
length = ms.Position;
bytes = ms.GetBuffer();
}
Util.PrintByteArray(bytes, (int)length);
using (var ms = new MemoryStream(bytes, false))
using (var br = new BinaryReader(ms)) {
for (int i = 0; i < values.Length; i++) {
var value = br.ReadInt64();
Console.WriteLine(value);
}
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string newFile = Server.MapPath("../") + "\\UploadFile\\" + Request.QueryString["FilePath"] + "";
FileStream newDoc = new FileStream(newFile, FileMode.Create, FileAccess.Write);
BinaryReader br = new BinaryReader(Request.InputStream);
BinaryWriter bw = new BinaryWriter(newDoc);
br.BaseStream.Seek(0, SeekOrigin.Begin);
bw.BaseStream.Seek(0, SeekOrigin.End);
int enterNo = 0;
int streamHeadLen = 0;
while (br.BaseStream.Position < br.BaseStream.Length)
{
streamHeadLen++;
char c = (char)br.ReadByte();
if (enterNo < enterCount)
{
if (c == '\n')
{
enterNo++;
}
}
else
{
break;
}
}
br.BaseStream.Seek(0, SeekOrigin.Begin);
string strTemp = System.Text.UTF8Encoding.Default.GetString(br.ReadBytes(streamHeadLen - 1));
while (br.BaseStream.Position < br.BaseStream.Length - 38)
{
bw.Write(br.ReadByte());
}
br.Close();
bw.Flush();
bw.Close();
string[] requestStrings = { "RecordID", "UserID" };
for (int i = 0; i < requestStrings.Length; i++)
{
string str = "Content-Disposition: form-data; name=\"" + requestStrings[i] + "\"\r\n\r\n";
int index = strTemp.IndexOf(str) + str.Length;
if (index != str.Length - 1)
{
for (int j = index; j < strTemp.Length; j++)
{
if (strTemp[j] != '\r')
this.requestValues[i] += strTemp[j];
else
break;
}
}
}
}
示例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
{
BinaryWriter bw2;
MemoryStream memstr2;
strLoc = "loc_t458x";
memstr2 = new MemoryStream();
bw2 = new BinaryWriter(memstr2);
bw2.Write("HelloWorld");
iCountTestcases++;
if(memstr2.Length != 11) {
iCountErrors++;
printerr( "Error_984y7! Incorrect stream length=="+memstr2.Length);
}
bw2.Flush();
iCountTestcases++;
if(memstr2.Length != 11) {
iCountErrors++;
printerr( "Error_8589v! Incorrect stream length after flush=="+memstr2.Length);
}
strLoc = "Loc_88v88";
memstr2 = new MemoryStream();
bw2 = new BinaryWriter(memstr2);
bw2.Close();
iCountTestcases++;
try {
bw2.Flush();
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_399c;! Unexpected exception exception thrown, exc=="+exc.ToString());
}
} catch (Exception exc_general ) {
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例7: CreatePhoto
void CreatePhoto()
{
try
{
FileStream _fileStream = new FileStream(Server.MapPath(Global.PROFILE_PICTURE + Userid + Global.PICTURE_EXTENSION_JPG), FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter _binaryWriter = new BinaryWriter(_fileStream);
_binaryWriter.Write(Convert.FromBase64String(Request.Form["imageData"]));
_binaryWriter.Flush();
_binaryWriter.Close();
_fileStream.Close();
}
catch (Exception Ex)
{
}
}
示例8: SendData
// This subroutine uses a StreamWriter to send a message to the user.
public void SendData(byte[] Data)
{
//lock ensure that no other threads try to use the stream at the same time.
lock (client.GetStream())
{
/*
StreamWriter writer = new StreamWriter(client.GetStream());
writer.Write(Data);// + (char) 13 + (char) 10);
// Make sure all data is sent now.
writer.Flush();*/
BinaryWriter writer = new BinaryWriter(client.GetStream());
writer.Write(Data);// + (char) 13 + (char) 10);
// Make sure all data is sent now.
writer.Flush();
}
}
示例9: Save
public int Save(string path, string dat,Encoding encode)
{
try
{
FileStream fs = new FileStream(Application.persistentDataPath + "/" + path, FileMode.Create, FileAccess.Write);
BinaryWriter sw = new BinaryWriter(fs);
var bin = aes.Encrypt(encode.GetBytes(dat));
sw.Write(bin);
sw.Flush();
sw.Close();
}
catch {
// セーブ失敗
return -1;
}
return 0;
}
示例10: WriteMessage
/// <summary>
/// 写数据
/// </summary>
void WriteMessage(byte[] message) {
MemoryStream ms = null;
using (ms = new MemoryStream()) {
ms.Position = 0;
BinaryWriter writer = new BinaryWriter(ms);
ushort msglen = (ushort)message.Length;
writer.Write(msglen);
writer.Write(message);
writer.Flush();
if (client != null && client.Connected) {
//NetworkStream stream = client.GetStream();
byte[] payload = ms.ToArray();
outStream.BeginWrite(payload, 0, payload.Length, new AsyncCallback(OnWrite), null);
} else {
Debug.LogError("client.connected----->>false");
}
}
}
示例11: CreatePhoto
void CreatePhoto()
{
try
{
string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);
FileStream fs = new FileStream("C:\\Webcam.jpg", FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs);
br.Write(photo);
br.Flush();
br.Close();
fs.Close();
}
catch (Exception Ex)
{
}
}
示例12: WriteMessage
private void WriteMessage(byte[] message)
{
MemoryStream ms = null;
using (ms = new MemoryStream())
{
ms.Position = 0;
BinaryWriter writer = new BinaryWriter(ms);
ushort msglen = (ushort)message.Length;
writer.Write(msglen);
writer.Write(message);
writer.Flush();
if (mTcpClient != null && mTcpClient.Connected)
{
byte[] payload = ms.ToArray();
mOutStream.BeginWrite(payload, 0, payload.Length, new AsyncCallback(OnWrite), null);
}
else
{
Debug.LogWarning("mTcpClient.connected----->>false");
}
}
}
示例13: ExportScenesToBINARY
public static void ExportScenesToBINARY()
{
string path = EditorUtility.SaveFilePanel("SaveBINARY", Application.dataPath, "Scenes_Config_BINARY", "txt");
FileStream fs = new FileStream(path, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes)
{
if (S.enabled)
{
EditorApplication.OpenScene(S.path);
foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
{
if (obj.transform.parent != null)
continue;
bw.Write(S.path);
bw.Write(obj.name);
short posx = (short)(obj.transform.position.x * 100);
bw.Write(posx);
bw.Write((short)(obj.transform.position.y * 100f));
bw.Write((short)(obj.transform.position.z * 100f));
bw.Write((short)(obj.transform.rotation.eulerAngles.x * 100f));
bw.Write((short)(obj.transform.rotation.eulerAngles.y * 100f));
bw.Write((short)(obj.transform.rotation.eulerAngles.z * 100f));
bw.Write((short)(obj.transform.localScale.x * 100f));
bw.Write((short)(obj.transform.localScale.y * 100f));
bw.Write((short)(obj.transform.localScale.z * 100f));
}
}
}
bw.Flush();
bw.Close();
fs.Close();
AssetDatabase.Refresh();
}
示例14: 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
{
BinaryWriter dw2 = null;
Stream fs2 = null;
BinaryReader dr2 = null;
FileInfo fil2 = null;
MemoryStream mstr = null;
Int64 i64a = 0;
Int64[] i64arr = new Int64[0];
int ii = 0;
String filName = s_strTFAbbrev+"Test.tmp";
strLoc = "Loc_8yfv7";
fil2 = new FileInfo(filName);
fs2 = fil2.Open(FileMode.Create);
dw2 = new BinaryWriter(fs2);
try {
i64arr = new Int64[] {
Int64.MinValue
,Int64.MaxValue
,0
,-10000
,10000
,-50
,50
};
for(ii = 0 ; ii < i64arr.Length ; ii++)
dw2.Write(i64arr[ii]);
dw2.Flush();
fs2.Close();
strLoc = "Loc_987hg";
fs2 = fil2.Open(FileMode.Open);
dr2 = new BinaryReader(fs2);
for(ii = 0 ; ii < i64arr.Length ;ii++) {
iCountTestcases++;
if((i64a = dr2.ReadInt64()) != i64arr[ii]) {
iCountErrors++;
printerr( "Error_298hg_"+ii+"! Expected=="+i64arr[ii]+" , got=="+i64a);
}
}
iCountTestcases++;
try {
i64a = dr2.ReadInt64();
iCountErrors++;
printerr( "Error_2389! Expected exception not thrown, i64a=="+i64a);
} catch (EndOfStreamException) {
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_3298h! Unexpected exception thrown, exc=="+exc.ToString());
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_278gy! Unexpected exception, exc=="+exc.ToString());
}
fs2.Close();
fil2.Delete();
strLoc = "Loc_98yss";
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
try {
i64arr = new Int64[] {
Int64.MinValue
,Int64.MaxValue
,0
,-10000
,10000
,-50
,50
};
for(ii = 0 ; ii < i64arr.Length ; ii++)
dw2.Write(i64arr[ii]);
dw2.Flush();
mstr.Position = 0;
strLoc = "Loc_287y5";
dr2 = new BinaryReader(mstr);
for(ii = 0 ; ii < i64arr.Length ;ii++) {
iCountTestcases++;
if((i64a = dr2.ReadInt64()) != i64arr[ii]) {
iCountErrors++;
printerr( "Error_48yf4_"+ii+"! Expected=="+i64arr[ii]+" , got=="+i64a);
}
}
iCountTestcases++;
try {
i64a = dr2.ReadInt64();
iCountErrors++;
printerr( "Error_2d847! Expected exception not thrown, i64a=="+i64a);
} catch (EndOfStreamException) {
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_238gy! Unexpected exception thrown, exc=="+exc.ToString());
}
} catch (Exception exc) {
iCountErrors++;
//.........这里部分代码省略.........
示例15: 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
{
BinaryWriter dw2 = null;
Stream fs2 = null;
BinaryReader dr2 = null;
FileInfo fil2 = null;
MemoryStream mstr = null;
String str2 = String.Empty;
String[] strArr = new String[0];
int ii = 0;
Byte[] tempbyt = new Byte[1];
String filName = s_strTFAbbrev+"Test.tmp";
StringBuilder sb = new StringBuilder();
String str1;
for(ii = 0 ; ii < 5 ; ii++)
sb.Append("abc");
str1 = sb.ToString();
strArr = new String[] {
"ABC"
,"\t\t\n\n\n\0\r\r\v\v\t\0\rHello"
,"This is a normal string"
,"[email protected]#$%^&&())_+_)@#"
,"ABSDAFJPIRUETROPEWTGRUOGHJDOLJHLDHWEROTYIETYWsdifhsiudyoweurscnkjhdfusiyugjlskdjfoiwueriye"
," "
,"\0\0\0\t\t\tHey\"\""
,"\u0022\u0011"
,str1
,String.Empty
};
strLoc = "Loc_8yfv7";
fil2 = new FileInfo(filName);
fs2 = fil2.Open(FileMode.Create);
dw2 = new BinaryWriter(fs2);
try {
for(ii = 0 ; ii < strArr.Length ; ii++)
dw2.Write(strArr[ii]);
dw2.Flush();
fs2.Close();
strLoc = "Loc_987hg";
fs2 = fil2.Open(FileMode.Open);
BinaryReader br = new BinaryReader( fs2);
for(ii = 0 ; ii < strArr.Length ;ii++) {
iCountTestcases++;
str2 = br.ReadString();
for(int jj = 0 ; jj < str2.Length ; jj++) {
if(str2[jj] != strArr[ii][jj]) {
iCountErrors++;
printerr( "Error_198hg_"+ii+"! Expected=="+strArr[ii][jj]+" , got=="+str2[jj]);
}
}
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_222gy! Unexpected exception, exc=="+exc.ToString());
}
fs2.Close();
fil2.Delete();
strLoc = "Loc_98yss";
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
try {
for(ii = 0 ; ii < strArr.Length ; ii++)
dw2.Write(strArr[ii]);
dw2.Flush();
mstr.Position = 0;
strLoc = "Loc_287y5";
dr2 = new BinaryReader(mstr);
BinaryReader br = new BinaryReader( mstr );
for(ii = 0 ; ii < strArr.Length ;ii++) {
iCountTestcases++;
str2 = br.ReadString();
for(int jj = 0 ; jj < str2.Length ; jj++) {
if(str2[jj] != strArr[ii][jj]) {
iCountErrors++;
printerr( "Error_298hg_"+ii+"! Expected=="+strArr[ii][jj]+" , got=="+str2[jj]);
}
}
}
} catch (Exception exc) {
iCountErrors++;
printerr( "Error_38f85! Unexpected exception, exc=="+exc.ToString());
}
mstr.Close();
strLoc = "Loc_489vy";
mstr = new MemoryStream();
dw2 = new BinaryWriter(mstr);
try {
dw2.Write((String)null);
iCountErrors++;
printerr( "Error_398ty! Expected exception not thrown");
} catch (ArgumentNullException) {
} catch (Exception exc) {
iCountErrors++;
//.........这里部分代码省略.........