本文整理汇总了C#中System.IO.MemoryStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.WriteByte方法的具体用法?C# MemoryStream.WriteByte怎么用?C# MemoryStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.WriteByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SubStream
public void SubStream()
{
var stream = new MemoryStream();
stream.WriteByte(0xff);
stream.Write(Misc.Members, 0, Misc.Members.Length);
stream.WriteByte(0xff);
stream.WriteByte(0xff);
stream.Position = 1;
var peReader1 = new PEReader(stream, PEStreamOptions.LeaveOpen, Misc.Members.Length);
Assert.Equal(Misc.Members.Length, peReader1.GetEntireImage().Length);
peReader1.GetMetadataReader();
stream.Position = 1;
var peReader2 = new PEReader(stream, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchMetadata, Misc.Members.Length);
Assert.Equal(Misc.Members.Length, peReader2.GetEntireImage().Length);
peReader2.GetMetadataReader();
stream.Position = 1;
var peReader3 = new PEReader(stream, PEStreamOptions.LeaveOpen | PEStreamOptions.PrefetchEntireImage, Misc.Members.Length);
Assert.Equal(Misc.Members.Length, peReader3.GetEntireImage().Length);
peReader3.GetMetadataReader();
}
示例2: ArrayToArrayText
/// <summary>
/// Serialise the enumeration or array.
/// </summary>
public byte[] ArrayToArrayText(NpgsqlNativeTypeInfo TypeInfo, object NativeData, Boolean forExtendedQuery, NativeToBackendTypeConverterOptions options, bool arrayElement)
{
MemoryStream array = new MemoryStream();
if (! forExtendedQuery)
{
if (! options.UseConformantStrings && options.Supports_E_StringPrefix)
{
array.WriteByte((byte)ASCIIBytes.E);
}
array.WriteByte((byte)ASCIIBytes.SingleQuote);
}
if (! WriteItemText(TypeInfo, NativeData, array, forExtendedQuery, options))
{
array.Write(ASCIIArrayByteArrays.EmptyArray, 0, ASCIIArrayByteArrays.EmptyArray.Length);
}
if (! forExtendedQuery)
{
array.WriteByte((byte)ASCIIBytes.SingleQuote);
}
return array.ToArray();
}
示例3: UrlEncodeAndWrite
// RFC: http://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
private void UrlEncodeAndWrite(string value, MemoryStream memoryStream)
{
foreach (char symbol in value)
{
if (unreservedChars.IndexOf(symbol) != -1)
{
memoryStream.WriteByte((byte)symbol);
}
else if (symbol == ' ')
{
memoryStream.WriteByte(plus);
}
else if (symbol < 255)
{
var encodedValue = Encoding.ASCII.GetBytes(String.Format("%{0:X2}", (byte)symbol));
memoryStream.Write(encodedValue, 0, encodedValue.Length);
}
else
{
var bytes = Encoding.UTF8.GetBytes(new[] { symbol });
foreach (var @byte in bytes)
{
var encodedValue = Encoding.ASCII.GetBytes(String.Format("%{0:X2}", @byte));
memoryStream.Write(encodedValue, 0, encodedValue.Length);
}
}
}
}
示例4: Application
/// <summary>
/// This is a javascript application.
/// </summary>
/// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
public Application(IDefaultPage page)
{
var m = new MemoryStream();
m.WriteByte((byte)'H');
m.WriteByte((byte)'E');
m.WriteByte((byte)'L');
m.WriteByte((byte)'L');
m.WriteByte((byte)'O');
var a = m.ToArray();
//Native.API.var_dump(a);
var w = new StringBuilder();
foreach (var item in a)
{
w.Append(item.ToString("x2"));
}
w.Append(", " + Convert.ToBase64String(a));
// {48454c4c4f, SEVMTE8=}
var e = w.ToString();
new IHTMLPre { innerText = e }.AttachToDocument();
@"Hello world".ToDocumentTitle();
// Send data from JavaScript to the server tier
service.WebMethod2(
@"A string from JavaScript.",
value => value.ToDocumentTitle()
);
}
示例5: Main
static void Main(string[] args)
{
MemoryStream m = new MemoryStream(64);
Console.WriteLine("Lenth: {0}\tPosition: {1}\tCapacity: {2}",
m.Length, m.Position, m.Capacity);
for (int i = 0; i < 64; i++)
{
m.WriteByte((byte)i);
}
string s = "Foo";
for (int i = 0; i < 3; i++)
{
m.WriteByte((byte)s[i]);
}
Console.WriteLine("Length: {0}\tPosition: {1}\tCapacity: {2}",
m.Length, m.Position, m.Capacity);
Console.WriteLine("\nContents:");
byte[] ba = m.GetBuffer();
foreach (byte b in ba)
{
Console.Write("{0,-3}", b);
}
FileStream fs = new FileStream("Goo.txt", FileMode.Create, FileAccess.Write);
m.WriteTo(fs);
fs.Close();
m.Close();
Console.ReadLine();
}
示例6: Write
public override void Write(ref NetworkStream netstream)
{
using (Stream stream = new MemoryStream())
{
// write Packet ID
stream.Write(BitConverter.GetBytes((ushort)this.ID), 0, 2);
// write Packet Size
stream.Write(BitConverter.GetBytes(this.BodySize), 0, 4);
// write UserID
stream.WriteByte((byte)this.UserID.Length);
stream.Write(Encoding.ASCII.GetBytes(this.UserID), 0, this.UserID.Length);
// write PCName
stream.WriteByte((byte)this.PCName.Length);
stream.Write(Encoding.ASCII.GetBytes(this.PCName), 0, this.PCName.Length);
// write AuthKey
stream.Write(BitConverter.GetBytes(this.AuthKey), 0, 4);
// copy stream to netstream
stream.Position = 0;
stream.CopyTo(netstream);
}
}
示例7: Write
public void Write(WebSocketOpCode opCode, byte[] payload, bool isLastFrame)
{
// best to write everything to a memory stream before we push it onto the wire
// not really necessary but I like it this way
using (MemoryStream memoryStream = new MemoryStream())
{
byte finBitSetAsByte = isLastFrame ? (byte)0x80 : (byte)0x00;
byte byte1 = (byte)(finBitSetAsByte | (byte)opCode);
memoryStream.WriteByte(byte1);
// NB, dont set the mask flag. No need to mask data from server to client
// depending on the size of the length we want to write it as a byte, ushort or ulong
if (payload.Length < 126)
{
byte byte2 = (byte)payload.Length;
memoryStream.WriteByte(byte2);
}
else if (payload.Length <= ushort.MaxValue)
{
byte byte2 = 126;
memoryStream.WriteByte(byte2);
BinaryReaderWriter.WriteUShort((ushort)payload.Length, memoryStream, false);
}
else
{
byte byte2 = 127;
memoryStream.WriteByte(byte2);
BinaryReaderWriter.WriteULong((ulong)payload.Length, memoryStream, false);
}
memoryStream.Write(payload, 0, payload.Length);
byte[] buffer = memoryStream.ToArray();
_stream.Write(buffer, 0, buffer.Length);
}
}
示例8: Encode
public IEnumerable<byte[]> Encode(byte[] bytes)
{
if (bytes.Length <= maxSize)
yield return bytes;
else
{
var messageChunkSize = maxSize - HeaderSize;
var chunksCount = bytes.Length / messageChunkSize + 1;
if(chunksCount > MaxChunkCount)
throw new ArgumentOutOfRangeException("bytes");
var remainingBytes = bytes.Length;
var messageId = idGenerator.GenerateId(bytes);
for (var chunkSequenceNumber = 0; chunkSequenceNumber < chunksCount; ++chunkSequenceNumber)
{
var chunkOffset = chunkSequenceNumber * messageChunkSize;
var chunkBytes = Math.Min(messageChunkSize, remainingBytes);
using (var stream = new MemoryStream(messageChunkSize))
{
stream.WriteByte(0x1e);
stream.WriteByte(0x0f);
stream.Write(messageId, 0, messageId.Length);
stream.WriteByte((byte)chunkSequenceNumber);
stream.WriteByte((byte)chunksCount);
stream.Write(bytes, chunkOffset, chunkBytes);
yield return stream.ToArray();
}
remainingBytes -= chunkBytes;
}
}
}
示例9: Make
public static byte[] Make(string scope)
{
Encoding encoding = Encoding.ASCII;
byte[] accessKey = encoding.GetBytes(Config.ACCESS_KEY);
byte[] secretKey = encoding.GetBytes(Config.SECRET_KEY);
byte[] upToken = null;
try
{
byte[] policyBase64 = encoding.GetBytes(Base64UrlSafe.Encode(scope));
byte[] digestBase64 = null;
using (HMACSHA1 hmac = new HMACSHA1(secretKey))
{
byte[] digest = hmac.ComputeHash(policyBase64);
digestBase64 = encoding.GetBytes(Base64UrlSafe.Encode(digest));
}
using (MemoryStream buffer = new MemoryStream())
{
buffer.Write(accessKey, 0, accessKey.Length);
buffer.WriteByte((byte)':');
buffer.Write(digestBase64, 0, digestBase64.Length);
buffer.WriteByte((byte)':');
buffer.Write(policyBase64, 0, policyBase64.Length);
upToken = buffer.ToArray();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
return upToken;
}
示例10: ToPacket
/// <summary>
/// Converts image to UPD packet payload
///
/// <--- 8 ---> <--- 8 --->
/// ┌────────────────────┬────────────────────┐
/// │Message type │Comp.-len in byte │
/// ├────────────────────┴────────────────────┤
/// │ Number of vectors │
/// ├─────────────────────────────────────────┤
/// │ │
/// ... Vectors! ...
/// │ │
/// └─────────────────────────────────────────┘
///
/// </summary>
/// <returns></returns>
public byte[] ToPacket()
{
using (MemoryStream ms = new MemoryStream())
{
// Write package type
ms.WriteByte((byte)PacketType.Image);
// Write component length
ms.WriteByte(COMPONENT_LENGTH);
// Write number of vectors
//ms.WriteByte((byte)_vectors.GetLength(0));
ms.Write(BitConverter.GetBytes(_vectors.GetLength(0)), 0, 2);
// Write vectors
for (int i = 0; i < _vectors.GetLength(0); i++)
{
ms.WriteByte(_vectors[i, 0]);
ms.WriteByte(_vectors[i, 1]);
ms.WriteByte(_vectors[i, 2]);
}
return ms.ToArray();
}
}
示例11: Explode
public byte[] Explode(int ExpectedSize)
{
int num;
byte[] buffer = new byte[ExpectedSize];
Stream stream = new MemoryStream(buffer);
while ((num = this.DecodeLit()) != -1)
{
if (num < 0x100)
{
stream.WriteByte((byte) num);
}
else
{
int length = num - 0xfe;
int num3 = this.DecodeDist(length);
if (num3 == 0)
{
goto Label_0067;
}
int num4 = ((int) stream.Position) - num3;
while (length-- > 0)
{
stream.WriteByte(buffer[num4++]);
}
}
}
Label_0067:
if (stream.Position == ExpectedSize)
{
return buffer;
}
byte[] destinationArray = new byte[stream.Position];
Array.Copy(buffer, 0, destinationArray, 0, destinationArray.Length);
return destinationArray;
}
示例12: fitFileWrite
public fitFileWrite(StreamReader file, FileStream fitFile)
{
MemoryStream memStream = new MemoryStream();
fitstream = new FitFieldStream(memStream);
memStream.Seek(HEADERSIZE, SeekOrigin.Begin);
while (!file.EndOfStream)
{
string[] str = file.ReadLine().Split(';');
if (str[0] == "data")
writeData(str, st);
if (str[0] == "def")
writeDefintion(str);
}
int size = (int)memStream.Position - HEADERSIZE;
memStream.Seek(0, SeekOrigin.Begin);
writeFitHeader(size, HEADERSIZE);
UInt16 crc = 0;
memStream.Seek(0, SeekOrigin.Begin);
while (memStream.Position < memStream.Length)
{
crc = fitstream.Get16(crc, (byte)memStream.ReadByte());
}
memStream.WriteByte((byte)(crc & 0xFF));
memStream.WriteByte((byte)(crc >> 8));
fitFile.Write(memStream.GetBuffer(), 0, (int)memStream.Position);
}
示例13: SerializeToByteArray
public byte[] SerializeToByteArray()
{
byte[] ret = new byte[ClassFile.DATA_SIZE + 1 + Name.Length];
for (int i = 0; i < ret.Length; ++i)
ret[i] = 254;
using (MemoryStream mem = new MemoryStream(ret))
{
mem.WriteByte(Packet.EncodeNumber(Name.Length, 1)[0]);
byte[] name = Encoding.ASCII.GetBytes(Name);
mem.Write(name, 0, name.Length);
mem.WriteByte(Base);
mem.WriteByte(Type);
mem.Write(Packet.EncodeNumber(Str, 2), 0, 2);
mem.Write(Packet.EncodeNumber(Int, 2), 0, 2);
mem.Write(Packet.EncodeNumber(Wis, 2), 0, 2);
mem.Write(Packet.EncodeNumber(Agi, 2), 0, 2);
mem.Write(Packet.EncodeNumber(Con, 2), 0, 2);
mem.Write(Packet.EncodeNumber(Cha, 2), 0, 2);
}
return ret;
}
示例14: Write
public override void Write(ref NetworkStream netstream)
{
using (Stream stream = new MemoryStream())
{
// write id
stream.Write(BitConverter.GetBytes((ushort)this.ID), 0, 2);
// write temporary size
stream.Write(BitConverter.GetBytes(0), 0, 4);
// store header size
int headersize = (int)stream.Position;
// write name
stream.WriteByte((byte)this.Name.Length);
stream.Write(Encoding.ASCII.GetBytes(this.Name), 0, this.Name.Length);
// write exists
stream.WriteByte(BitConverter.GetBytes(this.Exists)[0]);
// go back and write body size
this.BodySize = (uint)(stream.Length - headersize);
stream.Position = 2;
stream.Write(BitConverter.GetBytes(this.BodySize), 0, 4);
// copy stream to netstream
stream.Position = 0;
stream.CopyTo(netstream);
}
}
示例15: Receive
public string Receive()
{
int ib = 0x00;
MemoryStream ms = new MemoryStream();
for (; _stream.ReadByte() != 0x0B; ) ;
while (true) {
if (ib == 0x1C) {
ib = _stream.ReadByte();
if (ib == 0x0D)
break;
ms.WriteByte(0x1C);
ms.WriteByte((byte)ib);
}
else {
ib = _stream.ReadByte();
if (ib != 0x1C)
ms.WriteByte((byte)ib);
}
}
if (_version3) {
_stream.Write(ACK, 0, ACK.Length);
_stream.Flush();
}
#if SILVERLIGHT
return Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length);
#else
return Encoding.ASCII.GetString(ms.ToArray());
#endif
}