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


C# Stream.Compress方法代码示例

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


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

示例1: RepackXml

		public void RepackXml(XElement data, Stream destination)
		{
			using(var compressed = destination.Compress(true))
			using(var writer = XmlDictionaryWriter.CreateBinaryWriter(compressed, null, null, false))
			{
				data.Save(writer);
				writer.Flush();
				compressed.Flush();
			}
		}
开发者ID:cdrnet,项目名称:Lokad.Cloud,代码行数:10,代码来源:CloudFormatter.cs

示例2: Serialize

		public void Serialize(object instance, Stream destination)
		{
			var serializer = GetXmlSerializer(instance.GetType());

			using(var compressed = destination.Compress(true))
			using(var writer = XmlDictionaryWriter.CreateBinaryWriter(compressed, null, null, false))
			{
				serializer.WriteObject(writer, instance);
			}
		}
开发者ID:cdrnet,项目名称:Lokad.Cloud,代码行数:10,代码来源:CloudFormatter.cs

示例3: send

        private bool send(Opcode opcode, Stream stream)
        {
            lock (_forSend)
              {
            var sent = false;

            var src = stream;
            var compressed = false;
            try {
              if (_compression != CompressionMethod.NONE)
              {
            stream = stream.Compress (_compression);
            compressed = true;
              }

              sent = sendFragmented (opcode, stream, _client ? Mask.MASK : Mask.UNMASK, compressed);
            }
            catch (Exception ex) {
              _logger.Fatal (ex.ToString ());
              error ("An exception has occurred.");
            }
            finally {
              if (compressed)
            stream.Dispose ();

              src.Dispose ();
            }

            return sent;
              }
        }
开发者ID:kevleyski,项目名称:websocket-sharp,代码行数:31,代码来源:WebSocket.cs

示例4: Send

        // As server, used to broadcast
        internal void Send(Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
        {
            lock (_forSend)
              {
            try {
              Stream cached;
              if (!cache.TryGetValue (_compression, out cached))
              {
            cached = stream.Compress (_compression);
            cache.Add (_compression, cached);
              }
              else
            cached.Position = 0;

              sendFragmented (opcode, cached, Mask.UNMASK, _compression != CompressionMethod.NONE);
            }
            catch (Exception ex) {
              _logger.Fatal (ex.ToString ());
              error ("An exception has occurred.");
            }
              }
        }
开发者ID:kevleyski,项目名称:websocket-sharp,代码行数:23,代码来源:WebSocket.cs

示例5: Send

    // As server, used to broadcast
    internal void Send (Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
    {
      lock (_forSend) {
        try {
          Stream cached;
          if (!cache.TryGetValue (_compression, out cached)) {
            cached = stream.Compress (_compression);
            cache.Add (_compression, cached);
          }
          else {
            cached.Position = 0;
          }

          send (opcode, cached, _compression != CompressionMethod.None);
        }
        catch (Exception ex) {
          _logger.Fatal (ex.ToString ());
        }
      }
    }
开发者ID:greeduomacro,项目名称:uomap-client,代码行数:21,代码来源:WebSocket.cs

示例6: send

    private bool send (Opcode opcode, Stream stream)
    {
      lock (_forSend) {
        var src = stream;
        var compressed = false;
        var sent = false;
        try {
          if (_compression != CompressionMethod.None) {
            stream = stream.Compress (_compression);
            compressed = true;
          }

          sent = send (opcode, stream, compressed);
          if (!sent)
            error ("The sending has been interrupted.", null);
        }
        catch (Exception ex) {
          _logger.Fatal (ex.ToString ());
          error ("An exception has occurred while sending the data.", ex);
        }
        finally {
          if (compressed)
            stream.Dispose ();

          src.Dispose ();
        }

        return sent;
      }
    }
开发者ID:greeduomacro,项目名称:uomap-client,代码行数:30,代码来源:WebSocket.cs

示例7: Send

        // As server, used to broadcast
        internal void Send(Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
        {
            lock (_forSend) {
            try {
              Stream cached;
              if (!cache.TryGetValue (_compression, out cached)) {
            cached = stream.Compress (_compression);
            cache.Add (_compression, cached);
              }
              else
            cached.Position = 0;

              if (_readyState == WebSocketState.Open)
            sendFragmented (opcode, cached, Mask.Unmask, _compression != CompressionMethod.None);
            }
            catch (Exception ex) {
              _logger.Fatal (ex.ToString ());
              error ("An exception has occurred while sending a data.");
            }
              }
        }
开发者ID:jijamw,项目名称:websocket-sharp,代码行数:22,代码来源:WebSocket.cs

示例8: send

        private bool send(Opcode opcode, Stream stream)
        {
            lock (_forSend)
            {
                var src = stream;
                var compressed = false;
                var sent = false;
                try
                {
                    if (_compression != CompressionMethod.None)
                    {
                        stream = stream.Compress(_compression);
                        compressed = true;
                    }

                    sent = send(opcode, Mask.Unmask, stream, compressed);
                    if (!sent)
                        error("Sending a data has been interrupted.");
                }
                catch (Exception ex)
                {
                    error("An exception has occurred while sending a data.", ex);
                }
                finally
                {
                    if (compressed)
                        stream.Dispose();

                    src.Dispose();
                }

                return sent;
            }
        }
开发者ID:WJ-GitHub,项目名称:SocketHttpListener,代码行数:34,代码来源:WebSocket.cs

示例9: send

        private void send(Opcode opcode, Stream stream)
        {
            if (_compression == CompressionMethod.NONE || _perFrameCompress) {
                send(opcode, stream, false);
                return;
            }

            using (var compressed = stream.Compress(_compression)) {
                send(opcode, compressed, true);
            }
        }
开发者ID:rrmayer,项目名称:websocket-sharp,代码行数:11,代码来源:WebSocket.cs

示例10: Send

        // As server, used to broadcast
        internal void Send(Opcode opcode, Stream stream, Dictionary<CompressionMethod, Stream> cache)
        {
            lock (_forSend)
            {
                try
                {
                    Stream found;
                    if (!cache.TryGetValue(_compression, out found))
                    {
                        found = stream.Compress(_compression);
                        cache.Add(_compression, found);
                    }
                    else
                    {
                        found.Position = 0;
                    }

                    send(opcode, found, _compression != CompressionMethod.None);
                }
                catch (Exception ex)
                {
#if COMPAT
                    Log.Error(ex.ToString());
#else
                    ex.Log();
#endif
                }
            }
        }
开发者ID:unosquare,项目名称:embedio,代码行数:30,代码来源:WebSocket.cs


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