本文整理汇总了C#中System.IO.MemoryStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.Write方法的具体用法?C# System.IO.MemoryStream.Write怎么用?C# System.IO.MemoryStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了System.IO.MemoryStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessageData
public override IData GetMessageData(IList<Message> messages)
{
Beetle.Express.IData data = null;
byte[] buffer;
long index = 0;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
foreach (Message message in messages)
{
stream.Write(new byte[4], 0, 4);
short typevalue = TypeMapper.GetValue(message.Type);
if (typevalue == 0)
"{0} type value not registed".ThrowError<Exception>(message.Type);
byte[] typedata = BitConverter.GetBytes(typevalue);
stream.Write(typedata, 0, typedata.Length);
if (message.Value != null)
{
var serializer = SerializationContext.Default.GetSerializer(message.Type);
serializer.Pack(stream, message.Value);
}
buffer = stream.GetBuffer();
BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
index = stream.Position;
}
byte[] array = stream.ToArray();
data = new Data(array, array.Length);
data.Tag = messages;
}
return data;
}
示例2: Expand
/// <summary>
/// Expands the specified info.
/// </summary>
/// <param name="info">optional context and application specific information (can be a zero-length string)</param>
/// <param name="l">length of output keying material in octets (<= 255*HashLen)</param>
/// <returns>OKM (output keying material) of L octets</returns>
public byte[] Expand(byte[] info, int l)
{
if (info == null) info = new byte[0];
hmac.Key = this.prk;
var n = (int) System.Math.Ceiling(l * 1f / hashLength);
var t = new byte[n * hashLength];
using (var ms = new System.IO.MemoryStream())
{
var prev = new byte[0];
for (var i = 1; i <= n; i++)
{
ms.Write(prev, 0, prev.Length);
if (info.Length > 0) ms.Write(info, 0, info.Length);
ms.WriteByte((byte)(0x01 * i));
prev = hmac.ComputeHash(ms.ToArray());
Array.Copy(prev, 0, t, (i - 1) * hashLength, hashLength);
ms.SetLength(0); //reset
}
}
var okm = new byte[l];
Array.Copy(t, okm, okm.Length);
return okm;
}
示例3: GetMessagesData
public override IData GetMessagesData(IList<Message> messages)
{
IData data = null;
byte[] buffer;
long index = 0;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
foreach (Message message in messages)
{
stream.Write(new byte[4], 0, 4);
short typevalue = TypeMapper.GetValue(message.Type);
if (typevalue == 0)
throw new Exception (string.Format ("{0} type value not registed", message.Type));
byte[] typedata = BitConverter.GetBytes(typevalue);
stream.Write(typedata, 0, typedata.Length);
if (message.Value != null)
ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message.Value);
buffer = stream.GetBuffer();
BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
index = stream.Position;
}
byte[] array = stream.ToArray();
data = new Data(array,0, array.Length);
}
return data;
}
示例4: FillInternal
void FillInternal (DataRow row,IDataItem item)
{
if (item != null)
{
BaseImageItem bi = item as BaseImageItem;
if (bi != null) {
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream()){
Byte[] val = row[bi.ColumnName] as Byte[];
if (val != null) {
if ((val[78] == 66) && (val[79] == 77)){
memStream.Write(val, 78, val.Length - 78);
} else {
memStream.Write(val, 0, val.Length);
}
System.Drawing.Image image = System.Drawing.Image.FromStream(memStream);
bi.Image = image;
}
}
}
else
{
var dataItem = item as BaseDataItem;
if (dataItem != null) {
dataItem.DBValue = ExtractDBValue(row,dataItem).ToString();
}
return;
}
}
}
示例5: PngIconFromImage
public static Icon PngIconFromImage(Image img, int size = 16)
{
using (var bmp = new Bitmap(img, new Size(size, size)))
{
byte[] png;
using (var fs = new System.IO.MemoryStream())
{
bmp.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
fs.Position = 0;
png = fs.ToArray();
}
using (var fs = new System.IO.MemoryStream())
{
if (size >= 256) size = 0;
Pngiconheader[6] = (byte)size;
Pngiconheader[7] = (byte)size;
Pngiconheader[14] = (byte)(png.Length & 255);
Pngiconheader[15] = (byte)(png.Length / 256);
Pngiconheader[18] = (byte)(Pngiconheader.Length);
fs.Write(Pngiconheader, 0, Pngiconheader.Length);
fs.Write(png, 0, png.Length);
fs.Position = 0;
return new Icon(fs);
}
}
}
示例6: GetMessageData
public override IData GetMessageData(IList<Message> messages)
{
Beetle.Express.IData data = null;
byte[] buffer;
long index = 0;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
foreach (Message message in messages)
{
stream.Write(new byte[4], 0, 4);
byte[] typedata = MessageCenter.GetMessageTypeData(message.Type);
stream.Write(typedata, 0, typedata.Length);
if (message.Value != null)
{
var serializer = SerializationContext.Default.GetSerializer(message.Type);
serializer.Pack(stream, message.Value);
}
buffer = stream.GetBuffer();
BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
index = stream.Position;
}
data = new Data(stream.GetBuffer(), (int)stream.Length);
data.Tag = messages;
}
return data;
}
示例7: appendBytes
public byte[] appendBytes(byte[] original, string salt)
{
byte[] saltBytes = System.Text.Encoding.UTF8.GetBytes(salt);
var contentVar = new System.IO.MemoryStream();
contentVar.Write(original, 0, original.Length);
contentVar.Write(saltBytes, 0, saltBytes.Length);
return contentVar.ToArray();
}
示例8: CreateCSV
/// <summary>
/// Converts the <see cref="T:System.Data.IEnumerable"/> data source into CSV formatted data and returns that data as a <see cref="T:System.IO.MemoryStream"/> stream.
/// </summary>
/// <param name="data">The <see cref="T:System.Linq.IQueryable"/> object containing the data to be parsed.</param>
/// <param name="skipColumns">A <see cref="T:System.String[]"/> array indicating the names of columns that should not be included in the output.</param>
/// <param name="columnHeaders">A value of type <see cref="T:System.Boolean"/> indicating true if the resulting CSV file should include column headers. Otherwise, false.</param>
/// <returns>A <see cref="T:System.IO.MemoryStream"/> containing the resulting CSV file's binary data.</returns>
public static System.IO.MemoryStream CreateCSV(IEnumerable data, bool columnHeaders, params string[] skipColumns)
{
List<int> skipColIdx = new List<int>();
System.IO.MemoryStream strm = new System.IO.MemoryStream();
{
int rowNum = 0;
foreach (var d in data)
{
Type dType = d.GetType();
PropertyInfo[] props = dType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
// First, we're going to identify any columns we don't want to output (if any are specified).
if (rowNum == 0 && skipColumns.Length > 0)
for (int i = 0; i < props.Length; i++)
if (skipColumns.Contains(props[i].Name))
skipColIdx.Add(i);
// Now we're going to create the column headers, if we haven't done that already.
if (++rowNum == 1 && columnHeaders)
{
StringBuilder sbHdr = new StringBuilder();
for (int i = 0; i < props.Length; i++)
if (!props[i].PropertyType.Name.StartsWith("EntitySet") && !skipColIdx.Contains(i))
{
string colHdrName = props[i].Name;
if (colHdrName.Contains(',') || colHdrName.StartsWith(" ") || colHdrName.EndsWith(" "))
sbHdr.AppendFormat(",\"{0}\"", colHdrName);
else
sbHdr.Append("," + props[i].Name);
}
byte[] bufferHdr = System.Text.Encoding.UTF8.GetBytes(sbHdr.ToString().TrimStart(',') + "\r\n");
strm.Write(bufferHdr, 0, bufferHdr.Length);
}
StringBuilder sbRow = new StringBuilder();
for (int i = 0; i < props.Length; i++)
{
if (props[i].PropertyType.Name.StartsWith("EntitySet") || skipColIdx.Contains(i))
continue;
sbRow.Append(",");
object objfieldVal = props[i].GetValue(d, null);
string fieldVal = (objfieldVal != null) ? objfieldVal.ToString() : string.Empty;
if (fieldVal.Contains(',') || fieldVal.StartsWith(" ") || fieldVal.EndsWith(" "))
sbRow.AppendFormat("\"{0}\"", fieldVal);
else
sbRow.Append(fieldVal);
}
byte[] bufferRow = System.Text.Encoding.UTF8.GetBytes(sbRow.ToString().TrimStart(',') + "\r\n");
strm.Write(bufferRow, 0, bufferRow.Length);
}
}
return strm;
}
示例9: EncodeValue
public override byte[] EncodeValue(ScalarValue v)
{
if (v == ScalarValue.NULL)
{
return NULL_VALUE_ENCODING;
}
var buffer = new System.IO.MemoryStream();
var value_Renamed = (DecimalValue) v;
try
{
if (Math.Abs(value_Renamed.exponent) > 63)
{
Global.HandleError(Error.FastConstants.R1_LARGE_DECIMAL, "Encountered exponent of size " + value_Renamed.exponent);
}
byte[] temp_byteArray = INTEGER.Encode(new IntegerValue(value_Renamed.exponent));
buffer.Write(temp_byteArray, 0, temp_byteArray.Length);
byte[] temp_byteArray2 = INTEGER.Encode(new LongValue(value_Renamed.mantissa));
buffer.Write(temp_byteArray2, 0, temp_byteArray2.Length);
}
catch (System.IO.IOException e)
{
throw new RuntimeException(e);
}
return buffer.ToArray();
}
示例10: GetWordprocessingDocument
public WordprocessingDocument GetWordprocessingDocument()
{
var mem = new MemoryStream();
mem.Write(this.DocumentByteArray, 0, this.DocumentByteArray.Length);
WordprocessingDocument doc = WordprocessingDocument.Open(mem, true);
return doc;
}
示例11: recive
public string recive()
{
System.Text.Encoding enc = System.Text.Encoding.UTF8;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] resBytes = new byte[256];
int resSize = 0;
if (ns.DataAvailable)
{
do
{
//データの一部を受信する
resSize = ns.Read(resBytes, 0, resBytes.Length);
//受信したデータを蓄積する
ms.Write(resBytes, 0, resSize);
// 受信を続ける
} while (ns.DataAvailable || resBytes[resSize - 1] != '\n');
//受信したデータを文字列に変換
string resMsg = enc.GetString(ms.GetBuffer(), 0, (int)ms.Length);
ms.Close();
//末尾の\nを削除
resMsg = resMsg.TrimEnd('\n');
return resMsg;
}
else
{
return "0";
}
}
示例12: recv
public string recv()
{
System.Text.Encoding enc = System.Text.Encoding.UTF8;
//サーバーから送られたデータを受信する
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] resBytes = new byte[1];
int resSize;
ns.ReadTimeout = 100;
do
{
//データの一部を受信する
resSize = ns.Read(resBytes,0,1);
//Readが0を返した時はサーバーが切断したと判断
if (resSize == 0)
{
Console.WriteLine("サーバーが切断しました。");
return "";
}
if (resBytes[0] == ';')
{
break;
}
//受信したデータを蓄積する
ms.Write(resBytes, 0,1);
} while (ns.DataAvailable);
//受信したデータを文字列に変換
string resMsg = enc.GetString(ms.ToArray());
ms.Close();
Console.WriteLine(resMsg);
return resMsg;
}
示例13: DecodeResponse
private async Task<string> DecodeResponse(HttpWebResponse response)
{
foreach (System.Net.Cookie cookie in response.Cookies)
{
_cookies.Add(new Uri(response.ResponseUri.GetLeftPart(UriPartial.Authority)), cookie);
}
if (response.StatusCode == HttpStatusCode.Redirect)
{
var location = response.Headers[HttpResponseHeader.Location];
if (!string.IsNullOrEmpty(location))
return await Get(new Uri(location));
}
var stream = response.GetResponseStream();
var buffer = new System.IO.MemoryStream();
var block = new byte[65536];
var blockLength = 0;
do{
blockLength = stream.Read(block, 0, block.Length);
buffer.Write(block, 0, blockLength);
}
while(blockLength == block.Length);
return Encoding.UTF8.GetString(buffer.GetBuffer());
}
示例14: CSVAttributeNoHeaderTest
public void CSVAttributeNoHeaderTest()
{
var stream = new System.IO.MemoryStream();
var text = "A,B\r\nD,E";
var bytes = System.Text.Encoding.UTF8.GetBytes(text);
stream.Write(bytes, 0, bytes.Length);
stream.Position = 0;
var target = new CSVSource<TestClass>(stream, System.Text.Encoding.UTF8);
var firstLine = target.ReadNext();
Assert.AreEqual("A", firstLine.Col1);
Assert.AreEqual("B", firstLine.Col2);
//Without Index
stream = new System.IO.MemoryStream();
text = "A,B\r\nD,E";
bytes = System.Text.Encoding.UTF8.GetBytes(text);
stream.Write(bytes, 0, bytes.Length);
stream.Position = 0;
var target2 = new CSVSource<TestClass2>(stream, System.Text.Encoding.UTF8);
var firstLine2 = target2.ReadNext();
Assert.IsNull(firstLine2.Col1);
Assert.IsNull(firstLine2.Col2);
}
示例15: OtherWaysToGetReport
private static void OtherWaysToGetReport()
{
string report = @"d:\bla.rdl";
// string lalal = System.IO.File.ReadAllText(report);
// byte[] foo = System.Text.Encoding.UTF8.GetBytes(lalal);
// byte[] foo = System.IO.File.ReadAllBytes(report);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
using (System.IO.FileStream file = new System.IO.FileStream(report, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
byte[] bytes = new byte[file.Length];
file.Read(bytes, 0, (int)file.Length);
ms.Write(bytes, 0, (int)file.Length);
ms.Flush();
ms.Position = 0;
}
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("resource"))
{
using (System.IO.TextReader reader = new System.IO.StreamReader(ms))
{
// rv.LocalReport.LoadReportDefinition(reader);
}
}
using (System.IO.TextReader reader = System.IO.File.OpenText(report))
{
// rv.LocalReport.LoadReportDefinition(reader);
}
}
}