StreamHelper.cs
来源:互联网 发布:windows截图保存路径 编辑:程序博客网 时间:2024/04/30 06:41
- // ==++==
- //
- //
- // Copyright (c) 2002 Microsoft Corporation. All rights reserved.
- //
- // The use and distribution terms for this software are contained in the file
- // named license.txt, which can be found in the root of this distribution.
- // By using this software in any fashion, you are agreeing to be bound by the
- // terms of this license.
- //
- // You must not remove this notice, or any other, from this software.
- //
- //
- // ==--==
- //============================================================
- //
- // File: StreamHelper.cs
- //
- // Summary: Helper methods for streams.
- //
- //===========================================================
- using System;
- using System.IO;
- using System.Runtime.Remoting;
- namespace System.Runtime.Remoting.Channels
- {
- internal class StreamHelper
- {
- internal static void CopyStream(Stream source, Stream target)
- {
- if (source == null)
- return;
- // see if this is a ChunkedMemoryStream (we can do a direct write)
- ChunkedMemoryStream chunkedMemStream = source as ChunkedMemoryStream;
- if (chunkedMemStream != null)
- {
- chunkedMemStream.WriteTo(target);
- }
- else
- {
- // see if this is a MemoryStream (we can do a direct write)
- MemoryStream memContentStream = source as MemoryStream;
- if (memContentStream != null)
- {
- memContentStream.WriteTo(target);
- }
- else
- {
- // otherwise, we need to copy the data through an intermediate buffer
- byte[] buffer = CoreChannel.BufferPool.GetBuffer();
- int bufferSize = buffer.Length;
- int readCount = source.Read(buffer, 0, bufferSize);
- while (readCount > 0)
- {
- target.Write(buffer, 0, readCount);
- readCount = source.Read(buffer, 0, bufferSize);
- }
- CoreChannel.BufferPool.ReturnBuffer(buffer);
- }
- }
- } // CopyStream
- internal static void BufferCopy(byte[] source, int srcOffset,
- byte[] dest, int destOffset,
- int count)
- {
- if (count > 8)
- {
- Buffer.BlockCopy(source, srcOffset, dest, destOffset, count);
- }
- else
- {
- for (int co = 0; co < count; co++)
- dest[destOffset + co] = source[srcOffset + co];
- }
- } // BufferCopy
- } // StreamHelper
- } // namespace System.Runtime.Remoting.Channels
- StreamHelper.cs
- CS..........................
- cs
- cs
- cs
- Cs
- cs
- cs
- cs
- CS
- cs
- cs,
- cs
- cs
- cs
- cs
- cs
- cs
- 第五课 工厂方法模式
- BaseTransportHeaders.cs
- Linux下mount软盘映像文件
- 减肥失败
- ISO/IEC 27001(信息安全管理认证)业务介绍
- StreamHelper.cs
- Flex中利用 mx:States的例子
- asp.net网络书店网站源码
- SQL Server2000 索引结构及其使用 (索引使用经验总结)
- 好奇害死马
- SQL Server2000 索引结构及其使用 ( 一、深入浅出理解索引结构 )
- 几个.net开源项目
- 分布式查询
- 急求:分布式查询问题