本文整理汇总了C#中System.IO.MemoryStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.ReadByte方法的具体用法?C# System.IO.MemoryStream.ReadByte怎么用?C# System.IO.MemoryStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了System.IO.MemoryStream.ReadByte方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBackgroundPic
public static Bitmap GetBackgroundPic(I_DLE device, int address, byte mode, byte g_code_id, ref string desc)
{
RGS_SetBackgroundPic_frame frame=null;
System.IO.MemoryStream ms;
byte[] cmdText = new byte[] { 0x98, mode, g_code_id };
SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, address, cmdText);
device.Send(pkg);
if (pkg.result != CmdResult.ACK)
throw new Exception("cmd error:" + pkg.result);
byte frame_no = pkg.ReturnTextPackage.Text[3]; //0x98 frame_no
ms = new System.IO.MemoryStream(1024 * 1024*3);
for (int i = 1; i <= frame_no; i++)
{
cmdText = new byte[] {0x98,mode,g_code_id,(byte)i };
pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, address, cmdText);
device.Send(pkg);
frame = new RGS_SetBackgroundPic_frame(pkg.ReturnTextPackage);
ms.Write(frame.g_pattern_color, 0, frame.g_pattern_color.Length);
}
Bitmap pic = new Bitmap(frame.g_width, frame.g_height);
ms.Position = 0;
for(int y =0;y<frame.g_height;y++)
for (int x = 0; x < frame.g_width; x++)
{
// int r, g, b;
//r = ms.ReadByte();
//g = ms.ReadByte();
//b = ms.ReadByte();
pic.SetPixel(x, y, Color.FromArgb(ms.ReadByte(),ms.ReadByte(), ms.ReadByte()));
}
desc= System.Text.Encoding.Unicode.GetString(frame.g_desc);
ms.Dispose();
return pic;
}
示例2: Deserialize
public static object Deserialize(ArraySegment<byte> buffer)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer.Array,0,buffer.Count))
{
stream.Position = 0;
int type = stream.ReadByte();
if (type == 1)
{
return ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(stream, null, typeof(LogModel));
}
else
{
return ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(stream, null, typeof(StatModel));
}
}
}
示例3: GenerateHexDump
public static string GenerateHexDump(byte[] data) {
if (data == null || data.Length == 0)
return "";
int size = data.Length;
//ByteBuffer buffer = new ByteBuffer(data);
System.IO.MemoryStream buffer = new System.IO.MemoryStream(data);
//long remaining = (buffer.Length - buffer.Position);
string ascii = "";
//StringBuilder sb = new StringBuilder((buffer.Remaining * 3) - 1);
StringBuilder sb = new StringBuilder(((int)(buffer.Length - buffer.Position) * 3) - 1);
System.IO.StringWriter writer = new System.IO.StringWriter(sb);
int lineCount = 0;
for (int i = 0; i < size; i++) {
int val = buffer.ReadByte() & 0xFF;
writer.Write((char)highDigits[val]);
writer.Write((char)lowDigits[val]);
writer.Write(" ");
ascii += GetAsciiEquivalent(val) + " ";
lineCount++;
if (i == 0)
continue;
if ((i + 1) % 8 == 0)
writer.Write(" ");
if ((i + 1) % 16 == 0) {
writer.Write(" ");
writer.Write(ascii);
writer.WriteLine();
ascii = "";
lineCount = 0;
} else if (i == size - 1) {///HALF-ASSED ATTEMPT TO GET THE LAST LINE OF ASCII TO LINE UP CORRECTLY
//while(lineCount < 84) {
// writer.Write(" ");
// lineCount++;
//}
for (int y = lineCount; y < 25; y++) {
writer.Write(" ");
}
writer.Write(ascii);
writer.WriteLine();
}
}
return sb.ToString();
}
示例4: BeginReceiveCallback
// TODO: re-add encryption
private void BeginReceiveCallback(IAsyncResult ar)
{
Queue<Action> actionQueue = new Queue<Action>();
try
{
TcpClient lEndPoint = EndPoint;
Thread.MemoryBarrier();
if (lEndPoint == null)
{
("NoEndPoint for " + this.DisplayName).Log();
fragmentBuffer = new byte[0];
return;
}
int cb = lEndPoint.Client.EndReceive(ar);
if (cb == 0)
{
//Disconnect();
return;
}
byte[] receiveBuffer = ar.AsyncState as byte[];
if (fragmentBuffer.Length > 0)
{
var temp = new byte[cb + fragmentBuffer.Length];
fragmentBuffer.CopyTo(temp, 0);
Array.ConstrainedCopy(receiveBuffer, 0, temp, fragmentBuffer.Length, cb);
fragmentBuffer = new byte[0];
receiveBuffer = temp;
}
else
{
var temp = new byte[cb];
Array.ConstrainedCopy(receiveBuffer, 0, temp, 0, cb);
receiveBuffer = temp;
}
//("MCNC: receiveBuffer=" + System.Text.Encoding.ASCII.GetString(receiveBuffer)).Log();
var stream = new System.IO.MemoryStream(receiveBuffer);
using (var reader = new System.IO.BinaryReader(stream))
{
while (stream.Position < stream.Length && stream.ReadByte() == 0x1b)
{
var lastReadPosition = stream.Position - 1;
object o = null;
try
{
var len = reader.ReadUInt16();
byte[] payload = new byte[len];
stream.Read(payload, 0, payload.Length);
using (var payloadStream = new System.IO.MemoryStream(payload))
{
o = Serializer.ReadObject(payloadStream);
}
}
catch (Exception ex)
{
//("MCNC: lastReadPosition=" + lastReadPosition + " currentPosition=" + stream.Position).Log();
ex.Log();
// TODO: log/debug exception types thrown here, not documented on MSDN and it's not clear how to handle a buffer underrun in ReadObject
// TODO: if the exception is due to an unknown type, the fragmentBuffer logic will result in a deadlock on the network (always retrying a bad object)
o = null;
}
if (o == null)
{
stream.Seek(lastReadPosition, System.IO.SeekOrigin.Begin);
fragmentBuffer = new byte[stream.Length - lastReadPosition];
stream.Read(fragmentBuffer, 0, fragmentBuffer.Length);
break;
}
else
{
EnqueueAction(actionQueue, o);
}
}
}
if (actionQueue.Count == 0)
{
("NoActions for " + this.DisplayName).Log();
return;
}
#region process action queue
while (actionQueue.Count > 0)
{
Action action = actionQueue.Dequeue();
if (action != null)
{
try
{
action();
}
catch (Exception ex)
//.........这里部分代码省略.........
示例5: GetUserNotes
public static IEnumerable<TBUserNote> GetUserNotes(IWebAgent webAgent, string subName)
{
var request = webAgent.CreateGet(String.Format(ToolBoxUserNotesWiki, subName));
var reqResponse = webAgent.ExecuteRequest(request);
var response = JObject.Parse(reqResponse["data"]["content_md"].Value<string>());
int version = response["ver"].Value<int>();
string[] mods = response["constants"]["users"].Values<string>().ToArray();
string[] warnings = response["constants"]["warnings"].Values<string>().ToArray();
if (version < 6) throw new ToolBoxUserNotesException("Unsupported ToolBox version");
try
{
var data = Convert.FromBase64String(response["blob"].Value<string>());
string uncompressed;
using (System.IO.MemoryStream compressedStream = new System.IO.MemoryStream(data))
{
compressedStream.ReadByte();
compressedStream.ReadByte(); //skips first to bytes to fix zlib block size
using (DeflateStream blobStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
using (var decompressedReader = new System.IO.StreamReader(blobStream))
{
uncompressed = decompressedReader.ReadToEnd();
}
}
}
JObject users = JObject.Parse(uncompressed);
List<TBUserNote> toReturn = new List<TBUserNote>();
foreach (KeyValuePair<string, JToken> user in users)
{
var x = user.Value;
foreach (JToken note in x["ns"].Children())
{
TBUserNote uNote = new TBUserNote();
uNote.AppliesToUsername = user.Key;
uNote.SubName = subName;
uNote.SubmitterIndex = note["m"].Value<int>();
uNote.Submitter = mods[uNote.SubmitterIndex];
uNote.NoteTypeIndex = note["w"].Value<int>();
uNote.NoteType = warnings[uNote.NoteTypeIndex];
uNote.Message = note["n"].Value<string>();
uNote.Timestamp = UnixTimeStamp.UnixTimeStampToDateTime(note["t"].Value<long>());
uNote.Url = UnsquashLink(subName, note["l"].ValueOrDefault<string>());
toReturn.Add(uNote);
}
}
return toReturn;
}
catch (Exception e)
{
throw new ToolBoxUserNotesException("An error occured while processing Usernotes wiki. See inner exception for details", e);
}
}
示例6: Deserialize
public static TransparentStreamCanReadResponseMessage Deserialize(byte[] buffer)
{
if (buffer == null)
throw new ArgumentNullException ("buffer");
Guid streamID;
Guid requestID;
bool canRead;
Exception exception;
using (System.IO.MemoryStream MS = new System.IO.MemoryStream (buffer)) {
using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
streamID = new Guid (BR.ReadBytes (16));
requestID = new Guid (BR.ReadBytes (16));
canRead = BR.ReadBoolean ();
if (MS.ReadByte () == 1) {
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();
object deserializedObject = BF.Deserialize (MS);
if (deserializedObject is Exception) {
exception = (Exception)deserializedObject;
} else {
throw new Exception ("buffer contains an object of invalid type, expected System.Exception.");
}
} else
exception = null;
}
}
return new TransparentStreamCanReadResponseMessage (streamID, requestID, canRead, exception);
}
示例7: Deserialize
public static ObjectBusMessage Deserialize(byte[] bytes)
{
Guid requestID;
Table[] tables;
Exception exception;
using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
requestID = new Guid (BR.ReadBytes (16));
tables = new Table[BR.ReadInt32 ()];
for (int n = 0; n != tables.Length; n++) {
tables [n] = Table.Deserialize (BR.ReadBytes (BR.ReadInt32 ()));
}
if (MS.ReadByte () == 1) {
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();
object deserializedObject = BF.Deserialize (MS);
if (deserializedObject is Exception) {
exception = (Exception)deserializedObject;
} else if (deserializedObject is string) {
exception = new Exception ((string)deserializedObject);
} else {
throw new Exception ("buffer contains an object of invalid type, expected System.Exception.");
}
} else
exception = null;
return new GetTablesResponseMessage (requestID, tables, exception);
}
}
}
示例8: ProcessMjpegFrame
//.........这里部分代码省略.........
{
//If the quality > 127 there are usually Quantization Tables
if (Quality > 127)
{
if ((packet.Payload[offset++]) != 0)
{
//Must Be Zero is Not Zero
if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Break();
}
}
//Precision
PrecisionTable = (packet.Payload[offset++]);
#region RFC2435 Length Field
/*
The Length field is set to the length in bytes of the quantization
table data to follow. The Length field MAY be set to zero to
indicate that no quantization table data is included in this frame.
See section 4.2 for more information. If the Length field in a
received packet is larger than the remaining number of bytes, the
packet MUST be discarded.
When table data is included, the number of tables present depends on
the JPEG type field. For example, type 0 uses two tables (one for
the luminance component and one shared by the chrominance
components). Each table is an array of 64 values given in zig-zag
order, identical to the format used in a JFIF DQT marker segment.
For each quantization table present, a bit in the Precision field
specifies the size of the coefficients in that table. If the bit is
zero, the coefficients are 8 bits yielding a table length of 64
bytes. If the bit is one, the coefficients are 16 bits for a table
length of 128 bytes. For 16 bit tables, the coefficients are
presented in network byte order. The rightmost bit in the Precision
field (bit 15 in the diagram above) corresponds to the first table
and each additional table uses the next bit to the left. Bits beyond
those corresponding to the tables needed by the type in use MUST be
ignored.
*/
#endregion
//Length of all tables
ushort Length = (ushort)(packet.Payload[offset++] << 8 | packet.Payload[offset++]);
//If there is Table Data Read it
if (Length > 0)
{
tables = new ArraySegment<byte>(packet.Payload, offset, (int)Length);
offset += (int)Length;
}
else if (Length > packet.Payload.Length - offset)
{
continue; // The packet must be discarded
}
else // Create it from the Quality
{
tables = new ArraySegment<byte>(CreateQuantizationTables(Quality, type, PrecisionTable));
}
}
else // Create from the Quality
{
tables = new ArraySegment<byte>(CreateQuantizationTables(type, Quality, PrecisionTable));
}
byte[] header = CreateJFIFHeader(type, Width, Height, tables, PrecisionTable, RestartInterval);
Buffer.Write(header, 0, header.Length);
}
//Write the Payload data from the offset
Buffer.Write(packet.Payload, offset, packet.Payload.Length - offset);
}
//Check for EOI Marker
Buffer.Seek(-1, System.IO.SeekOrigin.Current);
if (Buffer.ReadByte() != Tags.EndOfInformation)
{
Buffer.WriteByte(Tags.Prefix);
Buffer.WriteByte(Tags.EndOfInformation);
}
//Go back to the beginning
Buffer.Position = 0;
//This article explains in detail what exactly happens: http://support.microsoft.com/kb/814675
//In short, for a lifetime of an Image constructed from a stream, the stream must not be destroyed.
//Image = new System.Drawing.Bitmap(System.Drawing.Image.FromStream(Buffer, true, true));
//DO NOT USE THE EMBEDDED COLOR MANGEMENT
// Image = System.Drawing.Image.FromStream(Buffer, false, true);
return Buffer.GetBuffer();
}
}
示例9: ParseAvcConfig
private static void ParseAvcConfig(
MediaStreamDescription stream,
List<MediaStreamSample> samples,
byte[] data)
{
System.IO.Stream ios = new System.IO.MemoryStream(data);
ios.Seek(5, System.IO.SeekOrigin.Begin);
int num_sps = ios.ReadByte() & 0x1f;
for (int i = 0; i < num_sps; ++i)
{
int len_sps = (ios.ReadByte() << 8) | ios.ReadByte();
byte[] sps = new byte[len_sps];
ios.Read(sps, 0, len_sps);
samples.Add(new MediaStreamSample(
stream,
new System.IO.MemoryStream(sps),
0,
len_sps,
0,
new Dictionary<MediaSampleAttributeKeys, string>()));
}
int num_pps = ios.ReadByte();
for (int i = 0; i < num_pps; ++i)
{
int len_pps = (ios.ReadByte() << 8) | ios.ReadByte();
byte[] pps = new byte[len_pps];
ios.Read(pps, 0, len_pps);
samples.Add(new MediaStreamSample(
stream,
new System.IO.MemoryStream(pps),
0,
len_pps,
0,
new Dictionary<MediaSampleAttributeKeys, string>()));
}
}
示例10: getPackedPktHead
/// <summary> Return the packed packet headers for a given tile.
///
/// </summary>
/// <returns> An input stream containing the packed packet headers for a
/// particular tile
///
/// </returns>
/// <exception cref="IOException">If an I/O error occurs while reading from the
/// encoder header stream
///
/// </exception>
public virtual System.IO.MemoryStream getPackedPktHead(int tile)
{
if (pkdPktHeaders == null)
{
int i, t;
pkdPktHeaders = new System.IO.MemoryStream[nTiles];
for (i = nTiles - 1; i >= 0; i--)
{
pkdPktHeaders[i] = new System.IO.MemoryStream();
}
if (nPPMMarkSeg != 0)
{
// If this is first time packed packet headers are requested,
// create packed packet headers from Nppm and Ippm fields
int nppm;
int nTileParts = tileOfTileParts.Count;
byte[] temp;
System.IO.MemoryStream pph;
System.IO.MemoryStream allNppmIppm = new System.IO.MemoryStream();
// Concatenate all Nppm and Ippm fields
for (i = 0; i < nPPMMarkSeg; i++)
{
byte[] temp_byteArray;
temp_byteArray = pPMMarkerData[i];
allNppmIppm.Write(temp_byteArray, 0, temp_byteArray.Length);
}
pph = new System.IO.MemoryStream(allNppmIppm.ToArray());
// Read all packed packet headers and concatenate for each
// tile part
for (i = 0; i < nTileParts; i++)
{
t = ((System.Int32) tileOfTileParts[i]);
// get Nppm value
nppm = (pph.ReadByte() << 24) | (pph.ReadByte() << 16) | (pph.ReadByte() << 8) | (pph.ReadByte());
temp = new byte[nppm];
// get ippm field
pph.Read(temp, 0, temp.Length); //SupportClass.ReadInput(pph, temp, 0, temp.Length);
byte[] temp_byteArray2;
temp_byteArray2 = temp;
pkdPktHeaders[t].Write(temp_byteArray2, 0, temp_byteArray2.Length);
}
}
else
{
int tp;
// Write all packed packet headers to pkdPktHeaders
for (t = nTiles - 1; t >= 0; t--)
{
for (tp = 0; tp < nTileParts[t]; tp++)
{
for (i = 0; i < nPPTMarkSeg[t][tp]; i++)
{
byte[] temp_byteArray3;
temp_byteArray3 = tilePartPkdPktHeaders[t][tp][i];
pkdPktHeaders[t].Write(temp_byteArray3, 0, temp_byteArray3.Length);
}
}
}
}
}
return new System.IO.MemoryStream(pkdPktHeaders[tile].ToArray());
}
示例11: CreateSystemNameTable
private void CreateSystemNameTable()
{
var table_size = BitConverter.ToUInt32( this.pm_.ReadMemory( this.system_table_config_.TableSizeAddress, 4 ), 0 );
var pointer_address = BitConverter.ToUInt32( this.pm_.ReadMemory( this.system_table_config_.PointerAddress, 4 ), 0 );
var table = this.pm_.ReadMemory( pointer_address, table_size );
using( var ms = new System.IO.MemoryStream( table ) ) {
for( var i=0; i<this.system_table_config_.RecordMaxLength; ++i ) {
var b = 0;
var name_data = new KOEI.WP7_2012.Horse.Name.NameData() {
Id = (uint)i,
Type = KOEI.WP7_2012.Horse.Name.NameDataType.SYSTEM,
};
using( var buff = new System.IO.MemoryStream() ) {
while( true ) {
if( ( b = ms.ReadByte() ) == -1 ) {
throw new Exception("馬名テーブルが解析できませんでした");
}
if( !IsKana( (byte)b ) && !IsEnglish( (byte)b ) ) {
throw new Exception("馬名テーブルが解析できませんでした(カナ)");
}
if( !IsKana( (byte)b ) ) {
ms.Seek( -1, System.IO.SeekOrigin.Current );
name_data.Kana = KOEI.WP7_2012.Helper.KoeiCode.ToString( buff.ToArray() );
break;
}
buff.WriteByte( (byte)b );
}
}
using( var buff = new System.IO.MemoryStream() ) {
while( true ) {
if( ( b = ms.ReadByte() ) == -1 ) {
break;
// throw new Exception("馬名テーブルが解析できませんでした");
}
if( !IsKana( (byte)b ) && !IsEnglish( (byte)b ) && i != this.system_table_config_.RecordMaxLength ) {
throw new Exception("馬名テーブルが解析できませんでした(英語)");
}
if( !IsEnglish( (byte)b ) ) {
ms.Seek( -1, System.IO.SeekOrigin.Current );
name_data.English = KOEI.WP7_2012.Helper.KoeiCode.ToString( buff.ToArray() );
break;
}
// ①とか余計な文字は無視する
if( ( b >= 0x57 && b <= 0x9E ) || b == 0xFD ) {
buff.WriteByte( (byte)b );
}
}
}
this.name_data_dic_[i] = name_data;
}
}
}
示例12: Deserialize
public static ObjectBusMessage Deserialize(byte[] buffer)
{
Guid requestID;
Guid chunks;
Exception exception;
using (System.IO.MemoryStream MS = new System.IO.MemoryStream (buffer, false)) {
using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
requestID = new Guid (BR.ReadBytes (16));
chunks = new Guid (BR.ReadBytes (16));
}
if (MS.ReadByte () == 1) {
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();
object deserializedObject = BF.Deserialize (MS);
if (deserializedObject is Exception) {
exception = (Exception)deserializedObject;
} else {
throw new Exception ("buffer contains an object of invalid type, expected System.Exception.");
}
} else
exception = null;
}
return new TopLevelChunksResponseMessage (requestID, chunks, exception);
}
示例13: TransfromXmlStringToHtml
public static byte[] TransfromXmlStringToHtml(System.Xml.Xsl.XslCompiledTransform xsl, System.Xml.XPath.XPathDocument xpathDoc, System.Xml.Xsl.XsltArgumentList xpathParameter = null)
{
byte[] result;
using (System.IO.Stream str = new System.IO.MemoryStream()) {
xsl.Transform(xpathDoc, xpathParameter, str);
str.Position = 0;
if (str.ReadByte() == bomBuffer[0] && str.ReadByte() == bomBuffer[1] && str.ReadByte() == bomBuffer[2]) {
str.Position = 3;
result = new byte[str.Length - 3];
} else {
str.Position = 0;
result = new byte[str.Length];
}
if (str.Length > 0) {
str.Read(result, 0, result.Length);
} else {
result = new byte[0];
}
xsl.TemporaryFiles.Delete();
return result;
}
}
示例14: Deserialize
public static ObjectBusMessage Deserialize(byte[] bytes)
{
Console.WriteLine ("GetRowsResponseMessage.Deserialize()");
Guid requestID;
Exception exception;
using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
requestID = new Guid (BR.ReadBytes (16));
int rc = BR.ReadInt32 ();
Console.WriteLine ("Response contains {0} rows", rc);
System.Collections.Generic.List<BD2.Conv.Frontend.Table.Row> rows = new System.Collections.Generic.List<BD2.Conv.Frontend.Table.Row> ();
for (int n = 0; n != rc; n++) {
Row r = Row.Deserialize (BR.ReadBytes (BR.ReadInt32 ()));
rows.Add (r);
}
if (MS.ReadByte () == 1) {
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();
object deserializedObject = BF.Deserialize (MS);
if (deserializedObject is Exception) {
exception = (Exception)deserializedObject;
} else {
throw new Exception ("buffer contains an object of invalid type, expected System.Exception.");
}
} else
exception = null;
return new GetRowsResponseMessage (requestID, rows, exception);
}
}
}