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


C# MemoryStream.ReadByte方法代码示例

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


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

示例1: DecodeAppleBitmaps

 static void DecodeAppleBitmaps(string[] paths)
 {
     foreach (string path in paths)
         if (File.Exists(path))
         {
             byte[] allbytes = File.ReadAllBytes(path);
             MemoryStream ms = new MemoryStream(allbytes);
             ms.Position = 0;
             int HeaderLength = ReadInt(ref ms);
             int ImageWidth = ReadInt(ref ms);
             int ImageHeight = ReadInt(ref ms);
             while (ms.Position < HeaderLength)
                 ms.ReadByte();
             Bitmap bmp = new Bitmap(ImageWidth, ImageHeight);
             for (int i = 0; i < ImageWidth * ImageHeight; i++)
             {
                 byte B = (byte)(ms.ReadByte() & 0xFF);
                 byte G = (byte)(ms.ReadByte() & 0xFF);
                 byte R = (byte)(ms.ReadByte() & 0xFF);
                 byte A = (byte)(ms.ReadByte() & 0xFF);
                 bmp.SetPixel(i % ImageWidth, i / ImageWidth, Color.FromArgb(A, R, G, B));
             }
             bmp.Save(path + ".png");
         }
 }
开发者ID:OrigamiTech,项目名称:AppleBitmap,代码行数:25,代码来源:Program.cs

示例2: getPacketVars

        /// <summary>
        /// Parses the given packet contained in the byte buffer array and returns
        /// a list of packets
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static LinkedList<AMFDataType> getPacketVars(byte[] buffer, int length, int offset)
        {
            //the linked list of packet vars
            LinkedList<AMFDataType> packetVars = new LinkedList<AMFDataType>();

            //read the header byte to determine size
            MemoryStream packetStream = new MemoryStream(buffer, offset, length);

            byte header = (byte)packetStream.ReadByte();
            header &= 0xC0; // isolate the size information

            //seek into the packet
            packetStream.Seek(AMFHeader.getHeaderSize(header) - 1, SeekOrigin.Current);

            while (packetStream.Position < length)
            {
                byte type = (byte)packetStream.ReadByte();
                Console.WriteLine("Looking at type: " + type);
                AMFDataType var = findAppropriateReader(type);
                var.read(packetStream);
                packetVars.AddLast(var);

            }
            

            return packetVars;

        }
开发者ID:tdhieu,项目名称:openvss,代码行数:35,代码来源:AMFPacket.cs

示例3: Read

        /// <summary>
        /// Convert a byte array to a DotSpatial.Topology geometry object
        /// </summary>
        /// <param name="data">the data from the BLOB column</param>
        /// <returns>the geometry object</returns>
        public override IGeometry Read(byte[] data)
        {
            //specialized Read() method for SpatiaLite
            using (Stream stream = new MemoryStream(data))
            {
                //read first byte
                BinaryReader reader = null;
                var startByte = stream.ReadByte(); //must be "0"
                var byteOrder = (ByteOrder)stream.ReadByte();

                try
                {
                    reader = (byteOrder == ByteOrder.BigEndian) ? new BeBinaryReader(stream) : new BinaryReader(stream);

                    int srid = reader.ReadInt32();
                    double mbrMinX = reader.ReadDouble();
                    double mbrMinY = reader.ReadDouble();
                    double mbrMaxX = reader.ReadDouble();
                    double mbrMaxY = reader.ReadDouble();
                    byte mbrEnd = reader.ReadByte();

                    return Read(reader);
                }
                finally
                {
                    if (reader != null)
                        reader.Close();
                }
            }
        }
开发者ID:DIVEROVIEDO,项目名称:DotSpatial,代码行数:35,代码来源:SpatiaLiteWkbReader.cs

示例4: Unsubscribe

        public Unsubscribe(List<byte> packetList)
        {
            TopicNames = new List<string>();
            packetList.RemoveAt(0);
            MemoryStream stream = new MemoryStream(packetList.ToArray());
            int remainingPacketLength = decodeRemainingLength(ref stream);
            PacketId = fromMsbLsb((byte)stream.ReadByte(), (byte)stream.ReadByte());

            while (remainingPacketLength > 0)
            {
                int thisTopicNameLength = fromMsbLsb((byte)stream.ReadByte(), (byte)stream.ReadByte());
                remainingPacketLength -= 2;
                string thisTopicName = string.Empty;
                for (var i = 0; i < thisTopicNameLength; i++)
                {
                    char c = (char)stream.ReadByte();
                    if(_validChars.Contains(c))
                        thisTopicName += c;
                    else
                        return;

                    remainingPacketLength--;
                }
                TopicNames.Add(thisTopicName);
            }
        }
开发者ID:Rooster212,项目名称:MQTTDistributedCoursework,代码行数:26,代码来源:Unsubscribe.cs

示例5: Parse

        public override void Parse(MemoryStream ms, ParseState state)
        {
            /* eat the try byte */
            ms.ReadByte();
            state.AlternateBreak = 102;
            while (Peek(ms) != 102)
            {
                Element nextElement = Element.GetNextElement(ms, state, IndentLevel, true);
                Body.Add(nextElement);
            }

            while (Peek(ms) != 103)
            {
                CatchElement catchElem = new CatchElement();
                catchElem.IndentLevel = IndentLevel;
                catchElem.Parse(ms, state);
                Catches.Add(catchElem);
            }

            /* eat the end try */
            ms.ReadByte();

            /* eat the semicolon */
            ms.ReadByte();
        }
开发者ID:tslater2006,项目名称:PeoplecodeDecoder,代码行数:25,代码来源:TryElement.cs

示例6: Parse

        public override void Parse(MemoryStream ms, ParseState state)
        {
            /* eat the While byte */
            ms.ReadByte();

            byte nextByte = Peek(ms);
            while (nextByte != 45) /* new line */
            {
                Condition.Add(Element.GetNextElement(ms, state, IndentLevel));
                nextByte = Peek(ms);
            }

            /* eat the new line */
            ms.ReadByte();

            nextByte = Peek(ms);
            state.AlternateBreak = 38;
            while (nextByte != 38) /* end-while */
            {
                Body.Add(Element.GetNextElement(ms, state, IndentLevel,true));
                nextByte = Peek(ms);
            }

            /* eat the end while */
            ms.ReadByte();

            /* eat the semicolon */
            ms.ReadByte();
        }
开发者ID:tslater2006,项目名称:PeoplecodeDecoder,代码行数:29,代码来源:WhileElement.cs

示例7: FlushBitsTest

        public void FlushBitsTest()
        {
            var mem = new MemoryStream();
            var writer = new SwfStreamWriter(mem);

            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(true);
            writer.WriteBit(false);

            writer.WriteBit(true);
            writer.WriteBit(true);
            writer.WriteBit(false);
            writer.WriteBit(false);
            writer.WriteBit(false);
            writer.WriteBit(false);

            writer.FlushBits();

            mem.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(0xaa, mem.ReadByte(), "Byte 0");
            Assert.AreEqual(0xc0, mem.ReadByte(), "Byte 1");

            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
开发者ID:liwq-net,项目名称:SwfLib,代码行数:30,代码来源:SwfStreamWriterTest.cs

示例8: Cipher

 internal static byte[] Cipher(byte[] buffer, ref byte[] key, bool decrypt)
 {
     var cipher = new Blowfish(key);
     var b = new byte[8];
     using (var m = new MemoryStream(buffer, true))
     {
         while (m.Position < m.Length)
         {
             //Endian swap 2 sets of 4 bytes
             for (int i = 3; i >= 0; i--)
             {
                 b[i] = (byte)m.ReadByte();
             }
             for (int i = 7; i >= 4; i--)
             {
                 b[i] = (byte)m.ReadByte();
             }
             //cipher the 8 bytes
             if (decrypt) cipher.Decipher(b, 8);
             else cipher.Encipher(b, 8);
             //Reset stream position to prepare for writing.
             m.Position -= 8;
             //Endian swap 4 bytes twice
             for (int i = 3; i >= 0; i--)
             {
                 m.WriteByte(b[i]);
             }
             for (int i = 7; i >= 4; i--)
             {
                 m.WriteByte(b[i]);
             }
         }
     }
     return buffer;
 }
开发者ID:8Ball360Haven,项目名称:MH4U_Cipher,代码行数:35,代码来源:Functions.cs

示例9: Parse

        public override void Parse(MemoryStream ms, ParseState state)
        {
            /* eat the declare byte */
            ms.ReadByte();

            StringBuilder sb = new StringBuilder();
            sb.Append("Declare Function ");
            ms.Position += 1;

            Element.GetNextElement(ms, state, -1).Write(sb);

            sb.Append(" ");

            /* eat the "peoplecode" byte */
            ms.ReadByte();

            sb.Append("PeopleCode ");

            Element.GetNextElement(ms, state, -1).Write(sb);

            sb.Append(" ");

            Element.GetNextElement(ms, state, -1).Write(sb);

            sb.Append(";\r\n");

            Value = sb.ToString();

            /* eat 2 bytes */
            ms.Position += 2;
        }
开发者ID:tslater2006,项目名称:PeoplecodeDecoder,代码行数:31,代码来源:DeclareFunctionElement.cs

示例10: ShouldDownloadFile

        public void ShouldDownloadFile()
        {
            var f = Encoding.ASCII.GetBytes(new string('x', 1048576));

            using (var fileContents = new MemoryStream(f))
            {
                var parent = Client.CreateFolder(FolderID.Root, "ParentFolder").ID;
                var file = Client.CreateFile(parent, "DownloadFileTest").ID;

                var progress = Client.StartUpload(file, fileContents);

                while (!progress.EOFReached)
                {
                    progress = Client.UploadContent(file, progress, fileContents);
                }
                Client.FinishUpload(file, progress);

                using (var downloadContents = Client.DownloadFileContent(file))
                {
                    fileContents.Seek(0, SeekOrigin.Begin);

                    int b1 = downloadContents.ReadByte(), b2 = fileContents.ReadByte();
                    do
                    {
                        Assert.AreEqual(b1, b2);
                        b1 = downloadContents.ReadByte();
                        b2 = fileContents.ReadByte();
                    } while (b1 != -1 && b2 != -1);
                }
            }
        }
开发者ID:aerofs,项目名称:aerofs-sdk-csharp,代码行数:31,代码来源:TestDownloadFile.cs

示例11: Publish

        public Publish(List<byte> packetList)
        {
            packetList.RemoveAt(0); // remove the type which we know already
            MemoryStream stream = new MemoryStream(packetList.ToArray());
            int numberOfChars = decodeRemainingLength(ref stream);

            int topicNameLength = fromMsbLsb((byte)stream.ReadByte(), (byte)stream.ReadByte());

            TopicName = string.Empty;
            for(int i = 0; i < topicNameLength; i++)
            {
                char c = (char) stream.ReadByte();

                if(c != '\0')
                    TopicName += c;
            }

            int remainingLength = numberOfChars - 2 - topicNameLength; // -2 for topic name length MSB+LSB
            Payload = string.Empty;
            for (int i = 0; i < remainingLength; i++)
            {
                char c = (char) stream.ReadByte();
                if(c != '\0')
                    Payload += c;
            }
            stream.Close();
        }
开发者ID:Rooster212,项目名称:MQTTDistributedCoursework,代码行数:27,代码来源:Publish.cs

示例12: ConvertFromPHP

        public static string ConvertFromPHP(string sPHP)
        {
            XmlDocument xml = new XmlDocument();
            xml.AppendChild(xml.CreateProcessingInstruction("xml" , "version=\"1.0\" encoding=\"UTF-8\""));
            xml.AppendChild(xml.CreateElement("USER_PREFERENCE"));
            try
            {
                byte[] abyPHP = Convert.FromBase64String(sPHP);
                StringBuilder sb = new StringBuilder();
                foreach(char by in abyPHP)
                    sb.Append(by);
                MemoryStream mem = new MemoryStream(abyPHP);

                string sSize = String.Empty;
                int nChar = mem.ReadByte();
                while ( nChar != -1 )
                {
                    char ch = Convert.ToChar(nChar);
                    if ( ch == 'a' )
                        PHPArray(xml, xml.DocumentElement, mem);
                    else if ( ch == 's' )
                        PHPString(mem);
                    else if ( ch == 'i' )
                        PHPInteger(mem);
                    nChar = mem.ReadByte();
                }
            }
            catch(Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
            }
            return xml.OuterXml;
        }
开发者ID:NALSS,项目名称:splendidcrm-99885,代码行数:33,代码来源:XmlUtil.cs

示例13: Connect

        public Connect(List<byte> packetList)
        {
            packetList.RemoveAt(0); // remove packet type
            MemoryStream stream = new MemoryStream(packetList.ToArray());
            int numberOfChars = decodeRemainingLength(ref stream);

            int protocolNameLength = fromMsbLsb((byte) stream.ReadByte(), (byte) stream.ReadByte());

            ProtocolName = string.Empty;
            for (int i = 0; i < protocolNameLength; i++)
            {
                char c = (char)stream.ReadByte();

                if (c != '\0')
                    ProtocolName += c;
            }

            ProtocolVersion = (byte) stream.ReadByte();
            // possibly check for the protocol level

            ConnectFlags = (byte) stream.ReadByte();

            KeepAliveTime = fromMsbLsb((byte) stream.ReadByte(), (byte) stream.ReadByte());

            int clientIdLength = fromMsbLsb((byte)stream.ReadByte(), (byte)stream.ReadByte());

            ClientId = string.Empty;
            for (int i = 0; i < clientIdLength; i++)
            {
                char c = (char)stream.ReadByte();
                if (c != '\0')
                    ClientId += c;
            }
        }
开发者ID:Rooster212,项目名称:MQTTDistributedCoursework,代码行数:34,代码来源:Connect.cs

示例14: Init

        private void Init(byte[] buffer)
        {
            var stream = new MemoryStream(buffer);
            stream.Seek(0, SeekOrigin.Begin);
            if (stream.ReadByte() != 2 && stream.ReadByte() != 0)
            {
                throw new InvalidDataException("Error Table Index");
            }
            else
            {
                while(ReadOne(stream))
                {
                    continue;
                }
                stream.Seek(195, SeekOrigin.Begin);
                if (stream.ReadByte() != 3)
                {
                    throw new InvalidDataException("Error Table Index");
                }
                else
                {

                }
            }
        }
开发者ID:sdzxwxlsj,项目名称:lsjutil,代码行数:25,代码来源:LDBTables.cs

示例15: ReadContents

 public override void ReadContents(byte[] bytes)
 {
     using (var ms = new MemoryStream(bytes))
     {
         var typeByte = (byte) ms.ReadByte();
         FrameType = (FrameType) (typeByte >> 4);
         Codec = (Codec) (typeByte & 0x0f);
         AVCType = AvcType.NotSet;
         if (Codec == Codec.AVC)
         {
             AVCType = (AvcType) ms.ReadByte();
             if (bytes.Length >= 5)
             {
                 switch (AVCType)
                 {
                     case AvcType.Nalu:
                         CompositionTime = Utils.GetUInt24(ms.ReadBytes(3), 0);
                         break;
                     default:
                         CompositionTime = Utils.GetUInt24(ms.ReadBytes(3), 0);
                         break;
                 }
             }
         }
         Payload = new byte[ms.Length - ms.Position];
         ms.Read(Payload, 0, Payload.Length);
     }
 }
开发者ID:rgrochowicz,项目名称:RTMPStreamReader,代码行数:28,代码来源:VideoTag.cs


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