本文整理汇总了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();
}
}
示例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);
}
}
示例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;
}
}
示例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.");
}
}
}
示例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 ());
}
}
}
示例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;
}
}
示例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.");
}
}
}
示例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;
}
}
示例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);
}
}
示例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
}
}
}