当前位置: 首页>>代码示例>>C#>>正文


C# MemoryStream.ReadByte方法代码示例

本文整理汇总了C#中MemoryStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ReadByte方法的具体用法?C# MemoryStream.ReadByte怎么用?C# MemoryStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemoryStream的用法示例。


在下文中一共展示了MemoryStream.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: unserialize

 public virtual void unserialize(MemoryStream stream)
 {
     byCmd=Convert.ToByte(stream.ReadByte());
     byParam=Convert.ToByte(stream.ReadByte());
     byte[] bpara=new byte[4];
     stream.Read(bpara,0,4);
     dwTimestamp = BitConverter.ToUInt32(bpara,0);
 }
开发者ID:minuowa,项目名称:Monos,代码行数:8,代码来源:BaseCommand.cs

示例2: DecodeLzma

 private static byte[] DecodeLzma(byte[] lzmaByteArray)
 {
     byte[] result = null;
     Decoder decoder = new Decoder();
     using (MemoryStream memoryStream = new MemoryStream(lzmaByteArray))
     {
         memoryStream.Seek(0L, SeekOrigin.Begin);
         using (MemoryStream memoryStream2 = new MemoryStream())
         {
             byte[] array = new byte[5];
             if (memoryStream.Read(array, 0, 5) != 5)
             {
                 throw new Exception("input .lzma is too short");
             }
             long num = 0L;
             for (int i = 0; i < 8; i++)
             {
                 int num2 = memoryStream.ReadByte();
                 if (num2 < 0)
                 {
                     throw new Exception("Can't Read 1");
                 }
                 num |= (long)((long)((ulong)((byte)num2)) << 8 * i);
             }
             decoder.SetDecoderProperties(array);
             long inSize = memoryStream.Length - memoryStream.Position;
             decoder.Code(memoryStream, memoryStream2, inSize, num, null);
             result = memoryStream2.ToArray();
         }
     }
     return result;
 }
开发者ID:softbreakers,项目名称:setup_soma_code,代码行数:32,代码来源:DecodeDeserializeUtils.cs

示例3: Start

    // Use this for initialization
    private void Start()
    {
        int count;
        byte[] byteArray;
        char[] charArray;
        UnicodeEncoding uniEncoding = new UnicodeEncoding();

        // Create the data to write to the stream. 
        byte[] firstString = uniEncoding.GetBytes(
            "Invalid file path characters are: ");
        byte[] secondString = uniEncoding.GetBytes(
            "123456789");

        using (MemoryStream memStream = new MemoryStream(100))
        {
            // Write the first string to the stream.
            memStream.Write(firstString, 0, firstString.Length);

            // Write the second string to the stream, byte by byte.
            count = 0;
            while (count < secondString.Length)
            {
                memStream.WriteByte(secondString[count++]);
            }

            // Write the stream properties to the console.
            Debug.Log(String.Format(
                "Capacity = {0}, Length = {1}, Position = {2}\n",
                memStream.Capacity.ToString(),
                memStream.Length.ToString(),
                memStream.Position.ToString()));

            // Set the position to the beginning of the stream.
            memStream.Seek(0, SeekOrigin.Begin);

            // Read the first 20 bytes from the stream.
            byteArray = new byte[memStream.Length];
            count = memStream.Read(byteArray, 0, 20);

            // Read the remaining bytes, byte by byte. 
            while (count < memStream.Length)
            {
                byteArray[count++] =
                    Convert.ToByte(memStream.ReadByte());
            }

            // Decode the byte array into a char array 
            // and write it to the console.
            charArray = new char[uniEncoding.GetCharCount(
                byteArray, 0, count)];
            uniEncoding.GetDecoder().GetChars(
                byteArray, 0, count, charArray, 0);
            Debug.Log(charArray);
        }
    }
开发者ID:benbon,项目名称:qjsbunitynew,代码行数:56,代码来源:StreamTest.cs

示例4: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        MemoryStream mem;
        int capacity;
        byte[] array;
        bool   canWrite;

        TestLibrary.TestFramework.BeginScenario("PosTest1: MemoryStream.Ctor(byte[],int,int,bool,bool)");

        try
        {
            canWrite = (TestLibrary.Generator.GetByte(-55)  % 2) == 0;
            capacity = (TestLibrary.Generator.GetInt32(-55) % 2048) + 1;
            array    = new byte[ capacity ];

            for (int i=0; i<array.Length; i++) array[i] = TestLibrary.Generator.GetByte(-55);

            mem = new MemoryStream(array, 0, array.Length, canWrite, true);

            for (int i=0; i<array.Length; i++)
            {
                byte val = (byte)mem.ReadByte();
                if (array[i] != val)
                {
                    TestLibrary.TestFramework.LogError("001", "Stream mismatch["+i+"]: Expected("+array[i]+") Actual("+val+")");
                    retVal = false;
                }
            }

            if (capacity != mem.Capacity)
            {
                TestLibrary.TestFramework.LogError("002", "Capacity mixmatch: Expected("+capacity+") Actual("+mem.Capacity+")");
                retVal = false;
            }

            if (canWrite != mem.CanWrite)
            {
                TestLibrary.TestFramework.LogError("003", "Can write unexpected: Expected("+canWrite+") Actual("+mem.CanWrite+")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:50,代码来源:memorystreamctor7.cs

示例5: ReadObject

 private static object ReadObject(MemoryStream stream, Hashtable ht, ref int hv, Hashtable rt, Encoding encoding)
 {
     stream.Seek(1, SeekOrigin.Current);
     int len = Int32.Parse(ReadNumber(stream));
     stream.Seek(1, SeekOrigin.Current);
     byte[] buf = new byte[len];
     stream.Read(buf, 0, len);
     string cn = encoding.GetString(buf);
     stream.Seek(2, SeekOrigin.Current);
     int n = Int32.Parse(ReadNumber(stream));
     stream.Seek(1, SeekOrigin.Current);
     Type type = GetType(cn);
     object o;
     if (type != null)
     {
         try
         {
             o = CreateInstance(type);
         }
         catch
         {
             o = new Hashtable(n);
         }
     }
     else
     {
         o = new Hashtable(n);
     }
     ht[hv++] = o;
     for (int i = 0; i < n; i++)
     {
         string key;
         switch (stream.ReadByte())
         {
             case __s: key = ReadString(stream, encoding); break;
             case __U: key = ReadUnicodeString(stream); break;
             default: ThrowError("Wrong Serialize Stream!"); return null;
         }
         if (key.Substring(0, 1) == "\0")
         {
             key = key.Substring(key.IndexOf("\0", 1) + 1);
         }
         if (o is Hashtable)
         {
             ((Hashtable)o)[key] = UnSerialize(stream, ht, ref hv, rt, encoding);
         }
         else
         {
             type.InvokeMember(key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetField, null, o, new object[] { UnSerialize(stream, ht, ref hv, rt, encoding) });
         }
     }
     stream.Seek(1, SeekOrigin.Current);
     MethodInfo __wakeup = null;
     try
     {
         __wakeup = o.GetType().GetMethod("__wakeup", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase, null, new Type[0], new ParameterModifier[0]);
     }
     catch { }
     if (__wakeup != null)
     {
         __wakeup.Invoke(o, null);
     }
     return o;
 }
开发者ID:wenysky,项目名称:deepinsummer,代码行数:64,代码来源:PHPSerializer.cs

示例6: ReadNumber

 private static string ReadNumber(MemoryStream stream)
 {
     StringBuilder sb = new StringBuilder();
     int i = stream.ReadByte();
     while (i != __Semicolon && i != __Colon)
     {
         sb.Append((char)i);
         i = stream.ReadByte();
     }
     return sb.ToString();
 }
开发者ID:wenysky,项目名称:deepinsummer,代码行数:11,代码来源:PHPSerializer.cs

示例7: ReadBoolean

 private static bool ReadBoolean(MemoryStream stream)
 {
     stream.Seek(1, SeekOrigin.Current);
     bool b = (stream.ReadByte() == __1);
     stream.Seek(1, SeekOrigin.Current);
     return b;
 }
开发者ID:wenysky,项目名称:deepinsummer,代码行数:7,代码来源:PHPSerializer.cs

示例8: ReadArray

 private static object ReadArray(MemoryStream stream, Hashtable ht, ref int hv, Hashtable rt, Encoding encoding)
 {
     stream.Seek(1, SeekOrigin.Current);
     int n = Int32.Parse(ReadNumber(stream));
     stream.Seek(1, SeekOrigin.Current);
     Hashtable h = new Hashtable(n);
     ArrayList al = new ArrayList(n);
     int r = hv;
     rt.Add(r, false);
     long p = stream.Position;
     ht[hv++] = h;
     for (int i = 0; i < n; i++)
     {
         object key, value;
         switch (stream.ReadByte())
         {
             case __i: key = Convert.ToInt32(ReadInteger(stream)); break;
             case __s: key = ReadString(stream, encoding); break;
             case __U: key = ReadUnicodeString(stream); break;
             default: ThrowError("Wrong Serialize Stream!"); return null;
         }
         value = UnSerialize(stream, ht, ref hv, rt, encoding);
         if (al != null)
         {
             if ((key is Int32) && (int)key == i)
             {
                 al.Add(value);
             }
             else
             {
                 al = null;
             }
         }
         h[key] = value;
     }
     if (al != null)
     {
         ht[r] = al;
         if ((bool)rt[r])
         {
             hv = r + 1;
             stream.Position = p;
             for (int i = 0; i < n; i++)
             {
                 int key;
                 switch (stream.ReadByte())
                 {
                     case __i: key = Convert.ToInt32(ReadInteger(stream)); break;
                     default: ThrowError("Wrong Serialize Stream!"); return null;
                 }
                 al[key] = UnSerialize(stream, ht, ref hv, rt, encoding);
             }
         }
     }
     rt.Remove(r);
     stream.Seek(1, SeekOrigin.Current);
     return ht[r];
 }
开发者ID:wenysky,项目名称:deepinsummer,代码行数:58,代码来源:PHPSerializer.cs

示例9: unserialize

 public override void unserialize(MemoryStream stream)
 {
     base.unserialize(stream);
     stream.Read(name,0,name.Length);
     err_code=Convert.ToByte(stream.ReadByte());
 }
开发者ID:minuowa,项目名称:Monos,代码行数:6,代码来源:SelectUserCmd.cs

示例10: GetIMGD

 /// <summary>
 ///     Return bitmap of the IMGD file
 ///     <param name="si">MemoryStream of the IMGD file/param>
 /// </summary>
 public static PicIMGD GetIMGD(MemoryStream si)
 {
     si.Position = 0L;
     if (si.ReadByte() != 73)
     {
         throw new NotSupportedException("!IMGD");
     }
     if (si.ReadByte() != 77)
     {
         throw new NotSupportedException("!IMGD");
     }
     if (si.ReadByte() != 71)
     {
         throw new NotSupportedException("!IMGD");
     }
     if (si.ReadByte() != 68)
     {
         throw new NotSupportedException("!IMGD");
     }
     var binaryReader = new BinaryReader(si);
     binaryReader.ReadInt32();
     int num = binaryReader.ReadInt32();
     int count = binaryReader.ReadInt32();
     int num2 = binaryReader.ReadInt32();
     int count2 = binaryReader.ReadInt32();
     si.Position = 28L;
     int num3 = binaryReader.ReadUInt16();
     int num4 = binaryReader.ReadUInt16();
     si.Position = 38L;
     int num5 = binaryReader.ReadUInt16();
     si.Position = 60L;
     int num6 = binaryReader.ReadByte();
     bool flag = num6 == 7;
     si.Position = num;
     byte[] array = binaryReader.ReadBytes(count);
     si.Position = num2;
     byte[] array2 = binaryReader.ReadBytes(count2);
     int num7 = num3;
     int num8 = num4;
     if (num5 == 19)
     {
         int num9 = num3/128;
         int num10 = num4/64;
         int bw = num9;
         int bh = num10;
         byte[] array3 = flag ? Reform.Decode8(Reform.Encode32(array, num9, num10), bw, bh) : array;
         var bitmap = new Bitmap(num7, num8, PixelFormat.Format8bppIndexed);
         BitmapData bitmapData = bitmap.LockBits(Rectangle.FromLTRB(0, 0, num7, num8),
             ImageLockMode.WriteOnly,
             PixelFormat.Format8bppIndexed);
         try
         {
             Marshal.Copy(array3, 0, bitmapData.Scan0, array3.Length);
         }
         finally
         {
             bitmap.UnlockBits(bitmapData);
         }
         var array4 = new byte[8192];
         Array.Copy(array2, 0, array4, 0, Math.Min(8192, array2.Length));
         byte[] array5 = array4;
         ColorPalette palette = bitmap.Palette;
         for (int i = 0; i < 256; i++)
         {
             int num11 = i;
             int num12 = Reform.pals.repl(i);
             palette.Entries[num12] = Color.FromArgb(Math.Min(255, array5[4*num11 + 3]*2), array5[4*num11],
                 array5[4*num11 + 1], array5[4*num11 + 2]);
         }
         bitmap.Palette = palette;
         return new PicIMGD(bitmap);
     }
     if (num5 == 20)
     {
         int num13 = num3/128;
         int num14 = num4/128;
         int bw2 = num13;
         int bh2 = num14;
         byte[] array6 = flag
             ? Reform.Decode4(Reform.Encode32(array, num13, num14), bw2, bh2)
             : HLUt.Swap(array);
         var bitmap2 = new Bitmap(num7, num8, PixelFormat.Format4bppIndexed);
         BitmapData bitmapData2 = bitmap2.LockBits(Rectangle.FromLTRB(0, 0, num7, num8),
             ImageLockMode.WriteOnly,
             PixelFormat.Format4bppIndexed);
         try
         {
             Marshal.Copy(array6, 0, bitmapData2.Scan0, array6.Length);
         }
         finally
         {
             bitmap2.UnlockBits(bitmapData2);
         }
         var array7 = new byte[8192];
         Array.Copy(array2, 0, array7, 0, Math.Min(8192, array2.Length));
         byte[] array8 = array7;
//.........这里部分代码省略.........
开发者ID:Truthkey,项目名称:OpenKH,代码行数:101,代码来源:IMGD_Z.cs

示例11: 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
     {
         MemoryStream ms2;
         Int32 ii = 0;
         Byte[] bytArr;
         Int32 i32;
         bytArr = new Byte[] {
                                 Byte.MinValue
                                 ,Byte.MaxValue
                                 ,100
                                 ,Byte.MaxValue-100
                             };
         strLoc = "Loc_398yc";
         ms2 = new MemoryStream();
         for(ii = 0 ; ii < bytArr.Length ; ii++)
             ms2.WriteByte(bytArr[ii]);
         ms2.Flush();
         ms2.Position = 0;
         ms2.Flush();
         for(ii = 0 ; ii < bytArr.Length ; ii++) 
         {
             iCountTestcases++;
             if((i32 = ms2.ReadByte()) != bytArr[ii]) 
             {
                 iCountErrors++;
                 printerr( "Error_38yv8_"+ii+"! Expected=="+bytArr[ii]+", got=="+i32);
             }
         }
         i32 = ms2.ReadByte();
         if(i32 != -1) 
         {
             iCountErrors++;
             printerr( "Error_238v8! -1 return expected, i32=="+i32);
         }
         ms2.Position = 0;
         for(ii = 0 ; ii < bytArr.Length; ii++)
             ms2.WriteByte(bytArr[ii]);
     } 
     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;
     }
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:61,代码来源:co5746writebyte.cs

示例12: DeserializePhotonStream

    private static object DeserializePhotonStream(MemoryStream inStream, short length)
    {
        int objectCount = inStream.ReadByte();
        object[] data = new object[objectCount];

        for (int i = 0; i < objectCount; i++)
        {
            int objectByteCount = inStream.ReadByte();
            byte[] serializedObject = new byte[objectByteCount];

            inStream.Read(serializedObject, 0, objectByteCount);

            data[i] = Protocol.Deserialize(serializedObject);
        }

        return new PhotonStream(false, data);
    }
开发者ID:Awesome-MQP,项目名称:Storybook,代码行数:17,代码来源:CustomTypes.cs

示例13: Decompress

 private static byte[] Decompress(byte[] inputBytes)
 {
     MemoryStream newInStream = new MemoryStream(inputBytes);
     Decoder decoder = new Decoder();
     newInStream.Seek(0, 0);
     MemoryStream newOutStream = new MemoryStream();
     byte[] properties2 = new byte[5];
     if (newInStream.Read(properties2, 0, 5) != 5)
         throw (new Exception("input .lzma is too short"));
     long outSize = 0;
     for (int i = 0; i < 8; i++)
     {
         int v = newInStream.ReadByte();
         if (v < 0)
             throw (new Exception("Can't Read 1"));
         outSize |= ((long)(byte)v) << (8 * i);
     }
     decoder.SetDecoderProperties(properties2);
     long compressedSize = newInStream.Length - newInStream.Position;
     decoder.Code(newInStream, newOutStream, compressedSize, outSize, null);
     byte[] b = newOutStream.ToArray();
     return b;
 }
开发者ID:ghasemgorji,项目名称:ExcelDnaUnPacker,代码行数:23,代码来源:ResourceHelper.cs

示例14: Unittest

        /// <summary>
        /// Helper function to
        /// </summary>
        /// <param name="message">A message printed to the console</param>
        /// <param name="input">The stream to test with</param>
        private static bool Unittest(string message, MemoryStream input)
        {
            Console.Write(message);

            const string PASSWORD_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#¤%&/()=?`*'^¨-_.:,;<>|";
            const int MIN_LEN = 1;
            const int MAX_LEN = 25;

            try
            {
                Random rnd = new Random();
                char[] pwdchars = new char[rnd.Next(MIN_LEN, MAX_LEN)];
                for (int i = 0; i < pwdchars.Length; i++)
                    pwdchars[i] = PASSWORD_CHARS[rnd.Next(0, PASSWORD_CHARS.Length)];

                input.Position = 0;

                using (MemoryStream enc = new MemoryStream())
                using (MemoryStream dec = new MemoryStream())
                {
                    Encrypt(new string(pwdchars), input, enc);
                    enc.Position = 0;
                    Decrypt(new string(pwdchars), enc, dec);

                    dec.Position = 0;
                    input.Position = 0;

                    if (dec.Length != input.Length)
                        throw new Exception(string.Format("Length differ {0} vs {1}", dec.Length, input.Length));

                    for (int i = 0; i < dec.Length; i++)
                        if (dec.ReadByte() != input.ReadByte())
                            throw new Exception(string.Format("Streams differ at byte {0}", i));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("FAILED: " + ex.Message);
                return false;
            }

            Console.WriteLine("OK!");
            return true;
        }
开发者ID:jurgen-kluft,项目名称:Vault,代码行数:49,代码来源:aescrypto.cs

示例15: ReadUnicodeString

 private static string ReadUnicodeString(MemoryStream stream)
 {
     stream.Seek(1, SeekOrigin.Current);
     int l = Int32.Parse(ReadNumber(stream));
     stream.Seek(1, SeekOrigin.Current);
     StringBuilder sb = new StringBuilder(l);
     int c;
     for (int i = 0; i < l; i++)
     {
         if ((c = stream.ReadByte()) == __Slash)
         {
             char c1 = (char)stream.ReadByte();
             char c2 = (char)stream.ReadByte();
             char c3 = (char)stream.ReadByte();
             char c4 = (char)stream.ReadByte();
             sb.Append((char)Int32.Parse(String.Concat(c1, c2, c3, c4), System.Globalization.NumberStyles.HexNumber));
         }
         else
         {
             sb.Append((char)c);
         }
     }
     stream.Seek(2, SeekOrigin.Current);
     return sb.ToString();
 }
开发者ID:wenysky,项目名称:deepinsummer,代码行数:25,代码来源:PHPSerializer.cs


注:本文中的MemoryStream.ReadByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。