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


C# Stream.Write方法代码示例

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


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

示例1: Write

        public static void Write(Stream stream, byte type, Stream exportStream)
        {
            stream.WriteByte(type);
            stream.Write(NetworkConverter.GetBytes((int)exportStream.Length), 0, 4);

            byte[] buffer = null;

            try
            {

                buffer = _bufferManager.TakeBuffer(1024 * 4);
                int length = 0;

                while ((length = exportStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    stream.Write(buffer, 0, length);
                }
            }
            finally
            {
                if (buffer != null)
                {
                    _bufferManager.ReturnBuffer(buffer);
                }
            }
        }
开发者ID:networkelements,项目名称:Library,代码行数:26,代码来源:ItemUtilities.cs

示例2: WriteOutput

    public static void WriteOutput(object data, Stream output, bool closeStreams )
    {
        if (data == output) return;

        XmlDocument xml = data as XmlDocument;
        if (xml != null)
        {
            XmlTextWriter xmlWriter = new XmlTextWriter(output, System.Text.Encoding.UTF8);
            xml.WriteTo(xmlWriter);
            xmlWriter.Flush();
        }

        Stream stream = data as Stream;
        if (stream != null)
        {
            stream.Seek(0, SeekOrigin.Begin);
            byte[] buffer = new byte[0x5000];
            int read;
            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                output.Write(buffer, 0, read);

            if ( closeStreams ) stream.Close();
        }

        byte[] block = data as byte[];
        if ( block != null && block.Length > 0 )
            output.Write( block, 0, block.Length );
    }
开发者ID:mbsky,项目名称:kub-engine,代码行数:28,代码来源:Types.cs

示例3: CopyTo

	/// <summary>
	/// Reads all the bytes from the current stream and writes them to the destination stream.
	/// </summary>
	/// <param name="original">The current stream.</param>
	/// <param name="destination">The stream that will contain the contents of the current stream.</param>
	/// <exception cref="System.ArgumentNullException">Destination is null.</exception>
	/// <exception cref="System.NotSupportedException">The current stream does not support reading.-or-destination does not support Writing.</exception>
	/// <exception cref="System.ObjectDisposedException">Either the current stream or destination were closed before the System.IO.Stream.CopyTo(System.IO.Stream) method was called.</exception>
	/// <exception cref="System.IO.IOException">An I/O error occurred.</exception>
	public static void CopyTo(this Stream original, Stream destination)
	{
		if (destination == null)
		{
			throw new ArgumentNullException("destination");
		}
		if (!original.CanRead && !original.CanWrite)
		{
			throw new ObjectDisposedException("ObjectDisposedException");
		}
		if (!destination.CanRead && !destination.CanWrite)
		{
			throw new ObjectDisposedException("ObjectDisposedException");
		}
		if (!original.CanRead)
		{
			throw new NotSupportedException("NotSupportedException source");
		}
		if (!destination.CanWrite)
		{
			throw new NotSupportedException("NotSupportedException destination");
		}
		
		byte[] array = new byte[4096];
		int count;
		while ((count = original.Read(array, 0, array.Length)) != 0)
		{
			destination.Write(array, 0, count);
		}
	}
开发者ID:ylyking,项目名称:mvx-unity-ngui,代码行数:39,代码来源:StreamExtensions.cs

示例4: CompressStream

    static void CompressStream(Stream from, Stream to)
    {
        byte[] src = new byte[from.Length];

        // read file
        if (from.Read(src, 0, src.Length) == src.Length)
        {
            int dstSize = DllInterface.aP_max_packed_size(src.Length);
            int wrkSize = DllInterface.aP_workmem_size(src.Length);

            // allocate mem
            byte[] dst = new byte[dstSize];
            byte[] wrk = new byte[wrkSize];

            // compress data
            int packedSize = DllInterface.aPsafe_pack(
                src,
                dst,
                src.Length,
                wrk,
                new DllInterface.CompressionCallback(ShowProgress),
                0
            );

            // write compressed data
            to.Write(dst, 0, packedSize);

            Console.WriteLine("compressed to {0} bytes", packedSize);
        }
    }
开发者ID:CCrashBandicot,项目名称:the-backdoor-factory,代码行数:30,代码来源:appack.cs

示例5: CopyStream

 public static void CopyStream(Stream input, Stream output)
 {
     var buffer = new byte[1024];
     int bytes;
     while ((bytes = input.Read(buffer, 0, 1024)) > 0)
         output.Write(buffer, 0, bytes);
 }
开发者ID:Johkar,项目名称:Hajk2,代码行数:7,代码来源:postproxy.aspx.cs

示例6: CopyStream

 private static void CopyStream(Stream source, Stream target)
 {
     const int bufSize = 0x1000;
     byte[] buf = new byte[bufSize];
     int bytesRead = 0;
     while ((bytesRead = source.Read(buf, 0, bufSize)) > 0)
         target.Write(buf, 0, bytesRead);
 }
开发者ID:xpekatt,项目名称:probatrondotnet,代码行数:8,代码来源:ZipUtils.cs

示例7: WriteTo

	/// <summary>
	/// Writes the input stream to the target stream.
	/// </summary>
	/// <param name="source" this="true">The source stream to write to the target stream.</param>
	/// <param name="target">The target stream to write to.</param>
	/// <returns>The written <paramref name="target"/> stream.</returns>
	public static void WriteTo(this Stream source, Stream target)
	{
		var buffer = new byte[BufferSize];
		var read = 0;
		while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
		{
			target.Write(buffer, 0, read);
		}
	}
开发者ID:victorgarciaaprea,项目名称:xunit.vsix,代码行数:15,代码来源:StreamWriteTo.cs

示例8: CopyTo

        // Summary:
        //     Reads all the bytes from the current stream and writes them to the destination
        //     stream.
        //
        // Parameters:
        //   destination:
        //     The stream that will contain the contents of the current stream.
        //
		// NOTE:
		//	This is a Stream member method in .NET 4
        public static void CopyTo(this Stream source, Stream destination)
		{
	       byte[] buffer = new byte[4096];
	       int n;
	       while ((n = source.Read(buffer, 0, buffer.Length)) != 0)
			{
	           destination.Write(buffer, 0, n);			
			}
		}
开发者ID:rtaylornc,项目名称:IntelliMediaCore,代码行数:19,代码来源:StreamExtensions.cs

示例9: CopyTo

 static void CopyTo(Stream source, Stream destination)
 {
     var array = new byte[81920];
     int count;
     while ((count = source.Read(array, 0, array.Length)) != 0)
     {
         destination.Write(array, 0, count);
     }
 }
开发者ID:whitestone-no,项目名称:open-serial-port-monitor,代码行数:9,代码来源:Common.cs

示例10: CopyToStream

 public static void CopyToStream(Stream src, Stream dst, byte[] buffer, int numBytes)
 {
     while (numBytes > 0)
     {
         int req = Math.Min(buffer.Length, numBytes);
         int read = src.Read(buffer, 0, req);
         dst.Write(buffer, 0, read);
         numBytes -= read;
     }
 }
开发者ID:CenzyGames,项目名称:Save-your-date-new,代码行数:10,代码来源:Utils.cs

示例11: CopyTo

        public static void CopyTo(this Stream from, Stream dest, byte[] buffer = null)
        {
            buffer = buffer ?? new byte[DefaultCopyBufferSize];
            var bufferSize = buffer.Length;

            int read;
            while ((read = from.Read(buffer, 0, bufferSize)) > 0) {
                dest.Write(buffer, 0, read);
            }
        }
开发者ID:katalist5296,项目名称:SanAndreasUnity,代码行数:10,代码来源:StreamEx.cs

示例12: writedouble

    public static void writedouble(Stream output, double val)
    {
        byte[] bytes = System.BitConverter.GetBytes(val);
#if StandAlone
#else
		if (System.BitConverter.IsLittleEndian)
			System.Array.Reverse(bytes);
#endif
        output.Write(bytes, 0, DOUBLE_LEN);
    }
开发者ID:learnUnity,项目名称:KU_NET,代码行数:10,代码来源:InOutStream.cs

示例13: WriteLong

        public static void WriteLong(long value, Stream stream, bool isLittleEndian)
        {
            byte[] buffer = BitConverter.GetBytes(value);
            if (BitConverter.IsLittleEndian && !isLittleEndian)
            {
                Array.Reverse(buffer);
            }

            stream.Write(buffer, 0, buffer.Length);
        }
开发者ID:shsouza,项目名称:sandbox,代码行数:10,代码来源:Websocket.cs

示例14: CopyStream

 public static void CopyStream(Stream src, Stream dst)
 {
     byte[] buff = new byte[4096];
       while (true)
       {
     int read = src.Read(buff, 0, 4096);
     if (read == 0)
       break;
     dst.Write(buff, 0, read);
       }
 }
开发者ID:danielgary,项目名称:xmlrpc-universal,代码行数:11,代码来源:util.cs

示例15: WriteBeyondEndTest

 public static bool WriteBeyondEndTest(Stream s)
 {
     Console.WriteLine("Write Beyond End test on "+s.GetType().Name);
     FileStream fs = s as FileStream;
     if (fs != null)
         Console.WriteLine("FileStream type is: "+(fs.IsAsync ? "asynchronous" : "synchronous"));
     long origLength = s.Length;        
     byte[] bytes = new byte[10];
     for(int i=0; i<bytes.Length; i++)
         bytes[i] = (byte) i;
     int spanPastEnd = 5;
     s.Seek(spanPastEnd, SeekOrigin.End);
     if (s.Position != s.Length + spanPastEnd)
         throw new Exception("Position is incorrect!  Seek(5, SeekOrigin.End) should leave us at s.Length + spanPastEnd ("+(s.Length + spanPastEnd)+"), but got: "+s.Position);
     Console.WriteLine("Original Length: "+origLength);
     s.Write(bytes, 0, bytes.Length);
     long pos = s.Position;
     if (pos != origLength + spanPastEnd + bytes.Length)
         throw new Exception(String.Format("After asynchronously writing beyond end of the stream, position is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     if (s.Length != origLength + spanPastEnd + bytes.Length)
         throw new Exception(String.Format("After asynchronously writing beyond end of the stream, Length is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     WritePastEndHelper(s, bytes, origLength, spanPastEnd, false);
     origLength = s.Length;
     s.Position = s.Length + spanPastEnd;
     s.WriteByte(0x42);
     long expected = origLength + spanPastEnd + 1;
     if (s.Position != expected)
     {
         iCountErrors++ ;
         throw new Exception("After WriteByte, Position was wrong!  got: "+s.Position+"  expected: "+expected);
     }
     if (s.Length != expected)
     {
         iCountErrors++ ;
         throw new Exception("After WriteByte, Length was wrong!  got: "+s.Length+"  expected: "+expected);
     }
     origLength = s.Length;
     s.Position = s.Length + spanPastEnd;
     IAsyncResult ar = s.BeginWrite(bytes, 0, bytes.Length, null, null);
     s.EndWrite(ar);
     pos = s.Position;
     if (pos != origLength + spanPastEnd + bytes.Length) 
     {
         iCountErrors++ ;
         throw new Exception(String.Format("After writing beyond end of the stream, position is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     }
     if (s.Length != origLength + spanPastEnd + bytes.Length) 
     {
         iCountErrors++;
         throw new Exception(String.Format("After writing beyond end of the stream, Length is now incorrect!  origLength: {0}  pos: {1}", origLength, pos));
     }
     WritePastEndHelper(s, bytes, origLength, spanPastEnd, true);
     return true;
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:54,代码来源:memorystream01.cs


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