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


C# DataReader.ReadBytes方法代码示例

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


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

示例1: ReadFrom

        public static AlternateStreamEntry ReadFrom(DataReader reader)
        {
            long startPos = reader.Position;

            long length = reader.ReadInt64();
            if (length == 0)
            {
                return null;
            }

            reader.Skip(8);

            AlternateStreamEntry result = new AlternateStreamEntry();
            result.Length = length;
            result.Hash = reader.ReadBytes(20);
            int nameLength = reader.ReadUInt16();
            if (nameLength > 0)
            {
                result.Name = Encoding.Unicode.GetString(reader.ReadBytes(nameLength + 2)).TrimEnd('\0');
            }
            else
            {
                result.Name = string.Empty;
            }

            if (startPos + length > reader.Position)
            {
                int toRead = (int)(startPos + length - reader.Position);
                reader.Skip(toRead);
            }

            return result;
        }
开发者ID:alexcmd,项目名称:DiscUtils,代码行数:33,代码来源:AlternateStreamEntry.cs

示例2: FromReader

    // Populate a datakey with data from a stream
    public void FromReader(DataReader reader, DataKey root, Logger logger)
    {
        // Read up to five bytes and reverse them
        byte[] data = reader.ReadBytes(5, false).Reverse().ToArray();

        logger.LogInfo("Read {0} bytes from stream", data.Length);

        // Add to key
        root.AddValue("data", data);
    }
开发者ID:michyer,项目名称:canape,代码行数:11,代码来源:basicstreamparser.cs

示例3: ReadFrames

            public static IEnumerable<DataFrame> ReadFrames(DataFrame firstFrame, DataReader reader)
            {
                if (firstFrame != null)
                {
                    yield return firstFrame;
                }

                byte[] data = reader.ReadBytes(HttpDataChunk.DEFAULT_CHUNK_SIZE, false);

                while (data.Length > 0)
                {
                    yield return new DataFrame(data);

                    data = reader.ReadBytes(HttpDataChunk.DEFAULT_CHUNK_SIZE, false);
                }
            }
开发者ID:michyer,项目名称:canape,代码行数:16,代码来源:HttpNetworkLayer.cs

示例4: ReadFrom

        public static DirectoryEntry ReadFrom(DataReader reader)
        {
            long startPos = reader.Position;

            long length = reader.ReadInt64();
            if (length == 0)
            {
                return null;
            }

            DirectoryEntry result = new DirectoryEntry();
            result.Length = length;
            result.Attributes = (FileAttributes)reader.ReadUInt32();
            result.SecurityId = reader.ReadUInt32();
            result.SubdirOffset = reader.ReadInt64();
            reader.Skip(16);
            result.CreationTime = reader.ReadInt64();
            result.LastAccessTime = reader.ReadInt64();
            result.LastWriteTime = reader.ReadInt64();
            result.Hash = reader.ReadBytes(20);
            reader.Skip(4);
            result.ReparseTag = reader.ReadUInt32();
            result.HardLink = reader.ReadUInt32();
            result.StreamCount = reader.ReadUInt16();
            int shortNameLength = reader.ReadUInt16();
            int fileNameLength = reader.ReadUInt16();

            if (fileNameLength > 0)
            {
                result.FileName = Encoding.Unicode.GetString(reader.ReadBytes(fileNameLength + 2)).TrimEnd('\0');
            }
            else
            {
                result.FileName = string.Empty;
            }

            if (shortNameLength > 0)
            {
                result.ShortName = Encoding.Unicode.GetString(reader.ReadBytes(shortNameLength + 2)).TrimEnd('\0');
            }
            else
            {
                result.ShortName = null;
            }

            if (startPos + length > reader.Position)
            {
                int toRead = (int)(startPos + length - reader.Position);
                reader.Skip(toRead);
            }

            if (result.StreamCount > 0)
            {
                result.AlternateStreams = new Dictionary<string, AlternateStreamEntry>();
                for (int i = 0; i < result.StreamCount; ++i)
                {
                    AlternateStreamEntry stream = AlternateStreamEntry.ReadFrom(reader);
                    result.AlternateStreams.Add(stream.Name, stream);
                }
            }

            return result;
        }
开发者ID:alexcmd,项目名称:DiscUtils,代码行数:63,代码来源:DirectoryEntry.cs

示例5: HTTPData

        public HTTPData(DataReader stm, Logger logger)
        {
            string header = stm.ReadLine();
            int contentLength = -1;
            bool chunked = false;
            byte[] body = null;
            bool connClose = false;

            if (header.Length == 0)
            {
                throw new EndOfStreamException();
            }

            HttpVersion ver = OnReadHeader(header.Trim(), logger);

            ReadHeaders(stm, logger);

            foreach (KeyDataPair<string> value in Headers)
            {
                if (value.Name.Equals("content-length", StringComparison.OrdinalIgnoreCase))
                {
                    contentLength = int.Parse(value.Value.ToString());
                    break;
                }
                else if (value.Name.Equals("transfer-encoding", StringComparison.OrdinalIgnoreCase))
                {
                    if (value.Value.ToString().Equals("chunked", StringComparison.OrdinalIgnoreCase))
                    {
                        chunked = true;
                        break;
                    }
                }
                else if (value.Name.Equals("connection", StringComparison.OrdinalIgnoreCase))
                {
                    // If the server indicates it will close the connection afterwards
                    if (value.Value.ToString().Equals("close", StringComparison.OrdinalIgnoreCase))
                    {
                        connClose = true;
                    }
                }
            }

            body = new byte[0];

            if (CanHaveBody())
            {
                if (chunked)
                {
                    List<byte> bodyData = new List<byte>();
                    byte[] data = ReadChunk(stm, logger);

                    while (data.Length > 0)
                    {
                        bodyData.AddRange(data);

                        data = ReadChunk(stm, logger);
                    }

                    body = bodyData.ToArray();
                }
                else if (contentLength > 0)
                {
                    body = stm.ReadBytes(contentLength);
                }
                else if ((contentLength < 0) && ((ver == HttpVersion.Http1_0) || connClose) && !IsRequest)
                {
                    // HTTP1.0 waits till end of stream (need to only do this on response though)
                    // Also sometimes happen on v1.1 if the client indicates that it is closing the connection
                    body = stm.ReadToEnd();
                }
            }

            Body = body;
        }
开发者ID:michyer,项目名称:canape,代码行数:74,代码来源:HTTPData.cs

示例6: ReadChunk

        private byte[] ReadChunk(DataReader stm, Logger logger)
        {
            string s = stm.ReadLine();
            if (s.Length == 0)
            {
                return new byte[0];
            }

            string lenstr = s.Trim();
            if (lenstr.Length == 0)
            {
                return new byte[0];
            }

            lenstr = lenstr.Split(new char[] { ';' }, 1)[0];
            int lenval = int.Parse(lenstr, NumberStyles.HexNumber);

            if (lenval > 0)
            {
                byte[] data = stm.ReadBytes(lenval);
                stm.ReadLine();

                return data;
            }
            else
            {
                // Read out final trailing data
                string line = stm.ReadLine();
                while ((line.Length > 0) && (line.Trim().Length > 0))
                {
                    line = stm.ReadLine();
                }
            }

            return new byte[0];
        }
开发者ID:michyer,项目名称:canape,代码行数:36,代码来源:HTTPData.cs

示例7: ReadChunkedEncoding

        private static byte[] ReadChunkedEncoding(DataReader stm, out string extension)
        {
            extension = null;

            string s = stm.ReadLine();
            if (s.Length == 0)
            {
                return new byte[0];
            }

            string lenstr = s.Trim();
            if (lenstr.Length == 0)
            {
                return new byte[0];
            }

            string[] values = lenstr.Split(new char[] { ';' }, 2);

            lenstr = values[0];

            if (values.Length > 1)
            {
                extension = values[1];
            }

            int lenval = int.Parse(lenstr, NumberStyles.HexNumber);

            if (lenval > 0)
            {
                byte[] data = stm.ReadBytes(lenval);
                stm.ReadLine();

                return data;
            }
            else
            {
                // Read out final trailing data
                string line = stm.ReadLine();
                while ((line.Length > 0) && (line.Trim().Length > 0))
                {
                    line = stm.ReadLine();
                }
            }

            return new byte[0];
        }
开发者ID:michyer,项目名称:canape,代码行数:46,代码来源:HttpResponseHeader.cs

示例8: ReadResourceRecord

        private static DNSRRBase ReadResourceRecord(byte[] data, DataReader reader)
        {
            DNSRRBase rr = null;

            string name = ReadString(data, reader);
            DNSType type = (DNSType)reader.ReadUInt16(false);
            DNSClass cls = (DNSClass)reader.ReadUInt16(false);
            uint ttl = reader.ReadUInt32(false);
            ushort rlen = reader.ReadUInt16(false);
            byte[] rdata = reader.ReadBytes(rlen);

            switch (type)
            {
                case DNSType.CNAME:
                    {
                        CNameDNSRR newRec = new CNameDNSRR(data, rdata);
                        rr = newRec;
                    }
                    break;
                case DNSType.A:
                    {
                        ADNSRR aRec = new ADNSRR(rdata);
                        rr = aRec;
                    }
                    break;
                case DNSType.AAAA:
                    {
                        AAAADNSRR aRec = new AAAADNSRR(rdata);
                        rr = aRec;
                    }
                    break;
                case DNSType.PTR:
                    {
                        PTRDNSRR aRec = new PTRDNSRR(data, rdata);
                        rr = aRec;
                    }
                    break;
                default:
                    {
                        UnknownDNSRR newRec = new UnknownDNSRR();
                        newRec.RData = rdata;
                        rr = newRec;
                    }
                    break;
            }

            rr.Name = name;
            rr.Class = cls;
            rr.Type = type;
            rr.TimeToLive = ttl;

            return rr;
        }
开发者ID:michyer,项目名称:canape,代码行数:53,代码来源:DNSPacket.cs


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