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


C# IStream.Read方法代码示例

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


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

示例1: ToMemoryStream

        public static unsafe MemoryStream ToMemoryStream(IStream comStream)
        {
            MemoryStream stream = new MemoryStream();
            byte[] pv = new byte[100];
            uint num = 0;

            IntPtr pcbRead = new IntPtr((void*)&num);

            do
            {
                num = 0;
                comStream.Read(pv, pv.Length, pcbRead);
                stream.Write(pv, 0, (int)num);
            }
            while (num > 0);
            return stream;
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:17,代码来源:StreamSupport.cs

示例2: ReadNameList

        private CatalogItem[] ReadNameList(IStream catalogHeaderStream, CatalogHeader header)
        {
            // 在Windows中,文件名最长好像只有256个Unicode字符
            // 所以1K的缓存应该很足够了
            var buffer = new byte[1024];
            var cbRead = Marshal.AllocCoTaskMem(4);
            var results = new CatalogItem[header.ThumbCount];
            var builder = new StringBuilder();

            try
            {
                for (int i = 0; i < header.ThumbCount; ++i)
                {
                    catalogHeaderStream.Read(buffer, 16, cbRead);
                    if (Marshal.ReadInt32(cbRead) != 16)
                        throw new InvalidDataException("文件夹的Thumb.db已经损坏!");

                    results[i].Reserved1 = BitConverter.ToInt32(buffer, 0);
                    results[i].ItemId = BitConverter.ToInt32(buffer, 4);
                    results[i].Modified = DateTime.FromFileTime(
                        BitConverter.ToInt64(buffer, 8));

                    Array.Clear(buffer, 0, 16);

                    do
                    {
                        catalogHeaderStream.Read(buffer, 2, cbRead);
                        builder.Append(BitConverter.ToChar(buffer, 0));

                    } while (buffer[0] != 0 || buffer[1] != 0);

                    builder.Length -= 1;
                    results[i].FileName = builder.ToString();
                    builder.Remove(0, builder.Length);

                    catalogHeaderStream.Read(buffer, 2, cbRead);
                    results[i].Reserved2 = BitConverter.ToInt16(buffer, 0);

                    Array.Clear(buffer, 0, 2);
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(cbRead);
            }

            return results;
        }
开发者ID:Prashant-Jonny,项目名称:phever,代码行数:48,代码来源:ThumbDbCom.cs

示例3: ReadToEnd

 public static byte[] ReadToEnd(IStream stream)
 {
     var buffer = new byte[stream.Length - stream.Position];
     stream.Read(buffer, 0, buffer.Length);
     return buffer;
 }
开发者ID:craigomatic,项目名称:Continuum,代码行数:6,代码来源:ByteReader.cs

示例4: Read

 public static byte[] Read(IStream stream, long length)
 {
     var buffer = new byte[length];
     stream.Read(buffer, 0, buffer.Length);
     return buffer;
 }
开发者ID:craigomatic,项目名称:Continuum,代码行数:6,代码来源:ByteReader.cs

示例5: ReadAllBytes

        private unsafe static void ReadAllBytes(IStream stream, out byte[] bytes, out int size)
        {
            const int STREAM_SEEK_SET = 0;

            size = GetStreamSize(stream);

            stream.Seek(0, STREAM_SEEK_SET, IntPtr.Zero);

            bytes = new byte[size];

            int bytesRead = 0;
            stream.Read(bytes, size, (IntPtr)(&bytesRead));

            if (bytesRead != size)
            {
                // TODO:
                throw new NotSupportedException();
            }
        }
开发者ID:NotYours180,项目名称:roslyn,代码行数:19,代码来源:SymBinder.cs

示例6: ToMemoryStream

 private unsafe MemoryStream ToMemoryStream(IStream comStream)
 {
     MemoryStream stream = new MemoryStream();
     byte[] pv = new byte[100];
     uint num = 0;
     IntPtr pcbRead = new IntPtr((void*) &num);
     comStream.Seek((long) 0, 0, IntPtr.Zero);
     do
     {
         num = 0;
         comStream.Read(pv, pv.Length, pcbRead);
         stream.Write(pv, 0, (int) num);
     } while (num > 0);
     return stream;
 }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:15,代码来源:ObjectDesigner.cs

示例7: PptStreamContainsEncryptedLabel

 static bool PptStreamContainsEncryptedLabel(IStream pptStream)
 {
     var ptrReadBytes = Marshal.AllocHGlobal(sizeof(ulong));
     try
     {
         int CHUNK_SIZE = 512;
         var lastChunk = new byte[CHUNK_SIZE];
         System.Runtime.InteropServices.ComTypes.STATSTG stat;
         pptStream.Stat(out stat, STATFLAG_DEFAULT);
         if (stat.cbSize > CHUNK_SIZE)
         {
             pptStream.Seek(stat.cbSize - CHUNK_SIZE, STREAM_SEEK_START, IntPtr.Zero);
         }
         pptStream.Read(lastChunk, CHUNK_SIZE, ptrReadBytes);
         var contentAsText = Encoding.ASCII.GetString(lastChunk);
         return contentAsText.Contains(ENCODED_LABEL_AS_TEXT);
     }
     finally
     {
         Marshal.FreeHGlobal(ptrReadBytes);
     }
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:22,代码来源:FileTypeIdentifier.cs

示例8: ReadHelloMessage

 /// <summary>
 /// Read a fixed length hello message and identifier from the client
 /// </summary>
 int ReadHelloMessage (IStream<byte,byte> stream, byte[] buffer)
 {
     // FIXME: Add better support for delayed receipt of hello message
     int offset = 0;
     for (int i = 0; i < 5; i++) {
         if (stream.DataAvailable) {
             offset += stream.Read (buffer, offset);
             if (offset == expectedHeader.Length + identifierLength)
                 break;
         }
         System.Threading.Thread.Sleep (50);
     }
     return offset;
 }
开发者ID:paperclip,项目名称:krpc,代码行数:17,代码来源:StreamServer.cs

示例9: GetBufferFromIStream

        private static byte[] GetBufferFromIStream(IStream comStream)
        {
            LARGE_INTEGER zeroPos;
            zeroPos.QuadPart = 0;
            ULARGE_INTEGER[] streamPosition = new ULARGE_INTEGER[1];
            comStream.Seek(zeroPos, (uint)STREAM_SEEK.STREAM_SEEK_CUR, streamPosition);
            comStream.Seek(zeroPos, (uint)STREAM_SEEK.STREAM_SEEK_SET, null);

            Microsoft.VisualStudio.OLE.Interop.STATSTG[] stat = new Microsoft.VisualStudio.OLE.Interop.STATSTG[1];
            comStream.Stat(stat, (uint)STATFLAG.STATFLAG_NONAME);

            int bufferLength = (int)stat[0].cbSize.QuadPart;
            byte[] buffer = new byte[bufferLength];
            uint bytesRead = 0;
            comStream.Read(buffer, (uint)buffer.Length, out bytesRead);

            // return the stream to its previous location
            LARGE_INTEGER newPos;
            newPos.QuadPart = (long)streamPosition[0].QuadPart;
            comStream.Seek(newPos, (uint)STREAM_SEEK.STREAM_SEEK_SET, null);

            return buffer;
        }
开发者ID:Graham-Pedersen,项目名称:IronPlot,代码行数:23,代码来源:WindowPane.cs

示例10: LoadStream

        private byte[] LoadStream(IStream stream)
        {
            long length;
            ErrorUtil.ThrowOnFailure(stream.GetLength(out length));

            byte[] result;
            ErrorUtil.ThrowOnFailure(stream.Read((int)length, out result));

            return result;
        }
开发者ID:netide,项目名称:netide,代码行数:10,代码来源:DiffViewerControl.cs


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