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


C# Stream.ReadInt方法代码示例

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


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

示例1: Receive

        /// <summary>
        /// Reconstructs remote data, given a delta stream and a random access / seekable input stream,
        /// all written to outputStream.
        /// </summary>
        /// <param name="deltaStream">sequential stream of deltas</param>
        /// <param name="inputStream">seekable and efficiently random access stream</param>
        /// <param name="outputStream">sequential stream for output</param>
        public void Receive(Stream deltaStream, Stream inputStream, Stream outputStream)
        {
            if (deltaStream == null) throw new ArgumentNullException("deltaStream");
            if (inputStream == null) throw new ArgumentNullException("inputStream");
            if (outputStream == null) throw new ArgumentNullException("outputStream");
            if (inputStream.CanSeek == false) throw new InvalidOperationException("inputStream must be seekable");

            int commandByte;
            while ((commandByte = deltaStream.ReadByte()) != -1)
            {
                if (commandByte == DeltaStreamConstants.NEW_BLOCK_START_MARKER)
                {
                    int length = deltaStream.ReadInt();
                    var buffer = new byte[length];
                    deltaStream.Read(buffer, 0, length);
                    outputStream.Write(buffer, 0, length);
                }
                else if (commandByte == DeltaStreamConstants.COPY_BLOCK_START_MARKER)
                {
                    long sourceOffset = deltaStream.ReadLong();
                    int length = deltaStream.ReadInt();
                    var buffer = new byte[length];
                    inputStream.Seek(sourceOffset, SeekOrigin.Begin);
                    inputStream.Read(buffer, 0, length);
                    outputStream.Write(buffer, 0, length);
                }
                else throw new IOException("Invalid data found in deltaStream");
            }
        }
开发者ID:billybit,项目名称:RsyncNet,代码行数:36,代码来源:DeltaStreamer.cs

示例2: Deserialize

        public override object Deserialize(Stream stream)
        {
            if (encryptionEnabled)
            {
                string descriptorName = stream.ReadUTF();
                int length = stream.ReadInt();
                byte[] buffer = stream.Read(length);

                string privateKey = serverAuthority.GenerateAgreementValue(remotePublicKey).ToString(16);
                RijndaelCrypto crypto = new RijndaelCrypto();

                Type t = registry.GetTypeForDescriptor(crypto.Decrypt(descriptorName, privateKey));
                if (t != null)
                {
                    return ReflectionHelper.InvokeStaticMethodOnType(t, "ParseFrom", crypto.Decrypt(buffer, privateKey));
                }

            }
            else
            {
                string descriptorName = stream.ReadUTF();

                int length = stream.ReadInt();
                byte[] buffer = stream.Read(length);

                Type t = registry.GetTypeForDescriptor(descriptorName);
                if (t != null)
                {
                    return ReflectionHelper.InvokeStaticMethodOnType(t, "ParseFrom", buffer);
                }
            }

            return null;
        }
开发者ID:soshimozi,项目名称:SocketServer,代码行数:34,代码来源:ProtoBuffEnvelope.cs

示例3: ReadFromStream

 public override void ReadFromStream(Stream aStream)
 {
     EntityID = aStream.ReadInt ();
     Type = aStream.ReadObjType ();
     X = aStream.ReadInt ();
     Y = aStream.ReadInt ();
     Z = aStream.ReadInt ();
 }
开发者ID:rbrian,项目名称:mccslib,代码行数:8,代码来源:Packets.cs

示例4: Unpack

        /* Unpack a GMP into a Bitmap */
        public override Bitmap Unpack(ref Stream data)
        {
            try
            {
                /* Get and set image variables */
                int width      = data.ReadInt(0xC); // Width
                int height     = data.ReadInt(0x8); // Height
                short bitDepth = data.ReadShort(0x1E); // Bit Depth
                short colors   = data.ReadShort(0x1C); // Pallete Entries

                /* Throw an exception if this is not an 8-bit gmp (for now) */
                if (bitDepth != 8)
                    throw new Exception();

                /* Set up the image */
                Bitmap image = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
                BitmapData imageData = image.LockBits(
                    new Rectangle(0, 0, width, height),
                    ImageLockMode.WriteOnly, image.PixelFormat);

                /* Read the data from the GMP */
                unsafe
                {
                    /* Write the palette */
                    ColorPalette palette = image.Palette;
                    for (int i = 0; i < colors; i++)
                        palette.Entries[i] = Color.FromArgb(data.ReadByte(0x20 + (i * 0x4) + 0x2), data.ReadByte(0x20 + (i * 0x4) + 0x1), data.ReadByte(0x20 + (i * 0x4)));

                    image.Palette = palette;

                    /* Start getting the pixels from the source image */
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            byte* rowData = (byte*)imageData.Scan0 + (y * imageData.Stride);
                            rowData[x] = data.ReadByte(0x20 + (colors * 0x4) + (width * height) - ((y + 1) * width) + x);
                        }
                    }
                }

                /* Unlock the bits now. */
                image.UnlockBits(imageData);

                return image;
            }
            catch
            {
                return null;
            }
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:52,代码来源:gmp.cs

示例5: FrameReader

        private FrameReader(Stream stream, bool streaming)
        {
            try
            {
                MessageOpcode = (MessageOpcodes)stream.ReadByte();
                int bodyLen = stream.ReadInt();
                if (streaming)
                {
                    _ms = new WindowedReadStream(stream, bodyLen);
                }
                else
                {
                    byte[] buffer = new byte[bodyLen];
                    if (0 < bodyLen)
                    {
                        stream.Read(buffer, 0, bodyLen);
                        _ms = new MemoryStream(buffer);
                    }
                }

                if (MessageOpcodes.Error == MessageOpcode)
                {
                    ThrowError();
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
开发者ID:lbucao,项目名称:cassandra-sharp,代码行数:31,代码来源:FrameReader.cs

示例6: Receive

 /// <summary>
 /// RSYNC file transfer with exchange of delta representatives (receiving end)
 /// </summary>
 /// <param name="stream">Connection stream</param>
 /// <param name="path">Path of file to transfer, must exist</param>
 public static void Receive(Stream stream, string path)
 {
     // Receive new file size
     int fileSizeNew = stream.ReadInt();
     int prevReadTimeout = stream.ReadTimeout;
     int prevWriteTimeout = stream.WriteTimeout;
     string tempPath = Shared.TempFile();
     var fileSizeOld = (int)new FileInfo(path).Length;
     var buffer = new byte[BufferSize];
     try
     {
         using (var fileStreamOld = new FileStream(path, FileMode.Open, FileAccess.Read))
         {
             Dictionary<int, List<Chunk>> remoteChunks = ReceiveChunkInformation(stream, fileSizeNew);
             stream.ReadTimeout = stream.WriteTimeout = fileSizeNew;
             List<Chunk> chunks = DiscoverChunksInLocalFile(remoteChunks, new C3C4TaylorsRollingChecksum(fileStreamOld, BlockSize), fileStreamOld,
                                                             fileSizeOld, buffer);
             stream.ReadTimeout = prevReadTimeout;
             stream.WriteTimeout = prevWriteTimeout;
             UniteCloseChunks(chunks);
             int chunksToRequest = AddChunksNotFoundInfo(chunks);
             chunksToRequest += AddChunkNotFoundTail(chunks, fileSizeNew);
             using (var fileStreamNew = new FileStream(tempPath, FileMode.CreateNew, FileAccess.Write))
             {
                 SendAndReceiveChunksAndRebuildFile(stream, chunks, fileStreamNew, fileStreamOld, chunksToRequest, buffer);
             }
         }
     }
     catch
     {
         if (File.Exists(tempPath))
             File.Delete(tempPath);
         stream.ReadTimeout = prevReadTimeout;
         stream.WriteTimeout = prevWriteTimeout;
     }
     // Verify file hash is as expected
     byte[] fileReceivedHash;
     using (var fs = File.OpenRead(tempPath))
     {
         fileReceivedHash = Md5.ComputeHash(fs);
     }
     // Receive hash of whole file
     var fileHash = new byte[16];
     stream.ForceRead(fileHash, 0, 16);
     if (!fileReceivedHash.AreEqual(fileHash))
     {
         File.Delete(tempPath);
         throw new Exception("File transfer error: file hash test failure");
     }
     // File transfer okay
     File.Delete(path);
     File.Move(tempPath, path);
 }
开发者ID:RenaissanceHust,项目名称:rdc,代码行数:58,代码来源:FileReceiver.cs

示例7: ReadFrom

        public override void ReadFrom(Stream stream, bool readName)
        {
            base.ReadFrom(stream, readName);

            Length = stream.ReadInt();

            Items = new byte[Length];

            for (int i = 0; i < Length; ++i)
            {
                Items[i] = (byte)stream.ReadByte();
            }
        }
开发者ID:andywhite37,项目名称:NCraft,代码行数:13,代码来源:ByteArrayTag.cs

示例8: Destream

 public static HashBlock[] Destream(Stream inputStream)
 {
     uint count = inputStream.ReadUInt();
     var hashBlocks = new HashBlock[count];
     for (int i = 0; i < count; ++i)
     {
         hashBlocks[i] = new HashBlock {Hash = new byte[16]};
         inputStream.Read(hashBlocks[i].Hash, 0, 16);
         hashBlocks[i].Length = inputStream.ReadInt();
         hashBlocks[i].Offset = inputStream.ReadLong();
         hashBlocks[i].Checksum = inputStream.ReadUInt();
     }
     return hashBlocks;
 }
开发者ID:billybit,项目名称:RsyncNet,代码行数:14,代码来源:HashBlockStreamer.cs

示例9: ReadFrom

        public override void ReadFrom(Stream stream, bool readName)
        {
            base.ReadFrom(stream, readName);

            ItemType = (byte)stream.ReadByte();
            Length = stream.ReadInt();
            Items = new Tag[Length];

            for (int i = 0; i < Length; ++i)
            {
                var tag = TagType.CreateTag(ItemType);
                tag.ReadFrom(stream, false);
                Items[i] = tag;
            }
        }
开发者ID:andywhite37,项目名称:NCraft,代码行数:15,代码来源:ListTag.cs

示例10: Deserialize

        public override void Deserialize(Stream stream, Type type, ref object value)
        {
            var elementType = GetElementType(type);
            var add = GetAddMethod(type, elementType).DelegateForCall();
            var clear = GetClearMethod(type);
            clear.Invoke(value);

            int count = stream.ReadInt();
            for (int i = 0; i < count; i++)
            {
                object item = null;
                ctx.Serializer.Deserialize_Main(stream, elementType, ref item);
                addArgs[0] = item;
                add.Invoke(value, addArgs);
            }
        }
开发者ID:flatlineteam,项目名称:relic-rush,代码行数:16,代码来源:CollectionSerializer.cs

示例11: Deserialize

        public override void Deserialize(Stream stream, Type type, ref object instance)
        {
            int count = stream.ReadInt();
            if (instance == null || ((Array)instance).Length != count)
            {
                instance = Array.CreateInstance(type.GetElementType(), count);
                ctx.Serializer.ReMark(instance);
            }

            var array = instance as IList;
            var elementType = type.GetElementType();
            for (int i = 0; i < count; i++)
            {
                object element = null;
                ctx.Serializer.Deserialize_Main(stream, elementType, ref element);
                array[i] = element;
            }
        }
开发者ID:srndpty,项目名称:VFW,代码行数:18,代码来源:ArraySerializer.cs

示例12: Deserialize

        public override object Deserialize(Stream stream)
        {
            string typeName = stream.ReadLine(MessageEncoding);

            int length = stream.ReadInt();
            byte[] messageBuffer = stream.Read(length);
            Type type = ReflectionHelper.FindType(typeName);

            if (type != null)
            {
                MemoryStream messageStream = new MemoryStream(messageBuffer);
                return Serializer.NonGeneric.Deserialize(type, messageStream);
            }
            else
            {
                throw new Exception("Invalid message type");
            }
        }
开发者ID:soshimozi,项目名称:SocketServer,代码行数:18,代码来源:PlainEnvelope.cs

示例13: FrameReader

        private FrameReader(Stream stream, bool streaming, bool tracing)
        {
            try
            {
                MessageOpcode = (MessageOpcodes)stream.ReadByte();
                int bodyLen = stream.ReadInt();
                if (streaming)
                {
                    _ms = new WindowedReadStream(stream, bodyLen);
                }
                else
                {
                    byte[] buffer = new byte[bodyLen];
                    if (0 < bodyLen)
                    {
                        // read whole frame in memory
                        int read = stream.Read(buffer, 0, bodyLen);
                        while (read != bodyLen)
                        {
                            read += stream.Read(buffer, read, bodyLen - read);
                        }
                        _ms = new MemoryStream(buffer);
                    }
                }

                if (tracing)
                {
                    // skip traceId
                    byte[] traceId = new byte[16];
                    int count = traceId.Length;
                    _ms.Read(traceId, 0, count);
                }

                if (MessageOpcodes.Error == MessageOpcode)
                {
                    ThrowError();
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
开发者ID:ananthonline,项目名称:cassandra-sharp,代码行数:44,代码来源:FrameReader.cs

示例14: CreateExceptionFromError

        private static Exception CreateExceptionFromError(Stream stream)
        {
            ErrorCodes code = (ErrorCodes) stream.ReadInt();
            string msg = stream.ReadString();

            switch (code)
            {
                case ErrorCodes.Unavailable:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadUShort();
                        int required = stream.ReadInt();
                        int alive = stream.ReadInt();
                        return new UnavailableException(msg, cl, required, alive);
                    }

                case ErrorCodes.WriteTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadUShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        string writeType = stream.ReadString();
                        return new WriteTimeOutException(msg, cl, received, blockFor, writeType);
                    }

                case ErrorCodes.ReadTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadUShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        bool dataPresent = 0 != stream.ReadByte();
                        return new ReadTimeOutException(msg, cl, received, blockFor, dataPresent);
                    }

                case ErrorCodes.Syntax:
                    return new SyntaxException(msg);

                case ErrorCodes.Unauthorized:
                    return new UnauthorizedException(msg);

                case ErrorCodes.Invalid:
                    return new InvalidException(msg);

                case ErrorCodes.AlreadyExists:
                    {
                        string keyspace = stream.ReadString();
                        string table = stream.ReadString();
                        return new AlreadyExistsException(msg, keyspace, table);
                    }

                case ErrorCodes.Unprepared:
                    {
                        byte[] unknownId = stream.ReadShortBytes();
                        return new UnpreparedException(msg, unknownId);
                    }

                default:
                    return new CassandraException(code, msg);
            }
        }
开发者ID:Jacky1,项目名称:cassandra-sharp,代码行数:59,代码来源:StreamingFrameReader.cs


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