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


C# Stream.Write方法代码示例

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


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

示例1: InternalWrite

        protected override void InternalWrite(Stream Target)
        {
            Target.Seek(0, SeekOrigin.Begin);
            Target.Write(ByteHelper.StringToByte("ID3"));
            //                Version 3.0   Flags  dummy size
            Target.Write(new byte[] { 3,0,  0,     0, 0, 0, 0  }, 0, 7);

            long totalFrameSize = 0;
            Stream frameStream = null;
            foreach(Frame f in Frames)
            {
                frameStream = FrameObjectToByteArray(f);
                totalFrameSize += frameStream.Length;
                frameStream.CopyTo(Target);
                frameStream.Flush();
            }
            Target.Seek(6, SeekOrigin.Begin);
            Target.Write(ByteHelper.GetByteArrayWith7SignificantBitsPerByteForInt((int)totalFrameSize));

            // frame fertig geschrieben jetzt müssen die daten rein =>
            // sourcestream an die stelle spulen und lesen bis endpos
            Target.Seek(DataStart, SeekOrigin.Begin);

            // Target.Copy(SourceStream, DataStart, DataEnd);

            Target.Flush();
            Target.Close();
        }
开发者ID:Epibatidin,项目名称:FLUX,代码行数:28,代码来源:ID3V23.cs

示例2: SignatureStream

 public SignatureStream( string signature, Stream baseStream )
 {
     Signature = signature;
     this.baseStream = baseStream;
     if ( CanRead )
     {
         byte [] sig = new byte [ signature.Length ];
         try { baseStream.Read ( sig, 0, sig.Length ); }
         catch { throw new ArgumentException (); }
         if ( Encoding.UTF8.GetString ( sig, 0, sig.Length ) != Signature )
             throw new ArgumentException ();
     }
     else if ( CanWrite && CanSeek )
     {
         long pos = baseStream.Position;
         baseStream.Position = 0;
         byte [] sig = Encoding.UTF8.GetBytes ( signature );
         baseStream.Write ( sig, 0, sig.Length );
         baseStream.Position = pos + signature.Length;
     }
     else if ( CanWrite && !CanSeek && baseStream.Position == 0 )
     {
         byte [] sig = Encoding.UTF8.GetBytes ( signature );
         baseStream.Write ( sig, 0, sig.Length );
     }
 }
开发者ID:Daramkun,项目名称:dWriter,代码行数:26,代码来源:SignatureStream.cs

示例3: Save

 public void Save(Stream stream)
 {
     stream.Write((byte)1);
     stream.Write((byte)m_mode);
     stream.Write(m_first);
     stream.Write(m_second);
 }
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:7,代码来源:TimestampMatching.cs

示例4: Compress

        public static int Compress(Stream input, Stream output)
        {
            var length = (int)(input.Length - input.Position);

            var varInt = new VarInt32(length).GetEncodedValue();
            output.Write(varInt, 0, varInt.Length);

            int bytesWritten = varInt.Length;

            int bytesToRead = Math.Min(length, CompressorConstants.BlockSize);

            var fragment = MemoryPool.Instance.Take(bytesToRead);

            int maxOutput = MaxCompressedOutput(bytesToRead);

            var block = MemoryPool.Instance.Take(maxOutput);

            while(length > 0)
            {
                var fragmentSize = input.Read(fragment, 0, bytesToRead);
                var hashTable = new HashTable(fragmentSize);

                int blockSize = CompressFragment(fragment, fragmentSize, hashTable, block);
                output.Write(block, 0, blockSize);
                bytesWritten += blockSize;

                length -= bytesToRead;
            }

            MemoryPool.Instance.Return(fragment);
            MemoryPool.Instance.Return(block);

            return bytesWritten;
        }
开发者ID:reuzel,项目名称:CqlSharp,代码行数:34,代码来源:Compressor.cs

示例5: Save

 /// <summary>
 /// Saves the token to a stream
 /// </summary>
 /// <param name="stream">the stream to save to</param>
 public void Save(Stream stream)
 {
     stream.WriteByte(1);
     stream.Write(CanWrite);
     stream.Write(CanRead);
     stream.Write(IsAdmin);
 }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:11,代码来源:SocketUserPermissions.cs

示例6: WriteToStreamAsync

        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content,
                                                TransportContext transportContext)
        {
            var callback = GetCallbackName();

            if (!String.IsNullOrEmpty(callback))
            {
                // select the correct encoding to use.
                Encoding encoding = SelectCharacterEncoding(content.Headers);

                // write the callback and opening paren.
                return Task.Factory.StartNew(() =>
                {
                    var bytes = encoding.GetBytes(callback + "(");
                    writeStream.Write(bytes, 0, bytes.Length);
                })
                    // then we do the actual JSON serialization...
                .ContinueWith(t => base.WriteToStreamAsync(type, value, writeStream, content, transportContext))

                // finally, we close the parens.
                .ContinueWith(t =>
                {
                    var bytes = encoding.GetBytes(")");
                    writeStream.Write(bytes, 0, bytes.Length);
                });
            }
            return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
        }
开发者ID:ahmetoz,项目名称:Photopia,代码行数:28,代码来源:JsonpMediaTypeFormatter.cs

示例7: Encrypt

        public async Task Encrypt(Stream input, Stream output)
        {
            _aes.GenerateIV();

            if (_cancelEvent.IsSet())
                return;

            byte[] vector = _aes.IV;
            byte[] vectorLength = BitConverter.GetBytes(vector.Length);
            output.Write(vectorLength, 0, 4);
            output.Write(vector, 0, vector.Length);

            if (_cancelEvent.IsSet())
                return;

            using (ICryptoTransform encryptor = _aes.CreateEncryptor())
            using (CryptoStream encryptionStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
            {
                if (_cancelEvent.IsSet())
                    return;

                await PatcherService.CopyAsync(input, encryptionStream, _cancelEvent, Progress);
                encryptionStream.FlushFinalBlock();
            }
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:25,代码来源:CryptoProvider.cs

示例8: SerializeTraceData

        public void SerializeTraceData(TraceData data, Stream stream)
        {
            /* write the magic to the raw stream */
            stream.Write(BitConverter.GetBytes(MAGIC), 0, sizeof(uint));
            stream.Write(BitConverter.GetBytes(VERSION), 0, sizeof(uint));

            /* Write the magic */
            WriteUint(MAGIC);

            /* Write the version */
            WriteUint(VERSION);

            SerializeStatistics(data.Statistics);

            SerializeStackTraces(data.StackTraces);

            SerializeSQLStatements(data.SQLStatements);

            SerializeExecutionCalls(data.AllExecutionCalls);

            WriteLong(data.MaxCallDepth);

            ms.Seek(0, SeekOrigin.Begin);

            using (DeflateStream def = new DeflateStream(stream, CompressionLevel.Optimal))
            {
                ms.CopyTo(def);
            }
        }
开发者ID:tslater2006,项目名称:Trace-Wizard,代码行数:29,代码来源:TraceSerializer.cs

示例9: Uint32ToByteStreamLe

 public static void Uint32ToByteStreamLe(uint val, Stream stream)
 {
     stream.Write((byte)(val >> 0));
     stream.Write((byte)(val >> 8));
     stream.Write((byte)(val >> 16));
     stream.Write((byte)(val >> 24));
 }
开发者ID:Eropi4,项目名称:clMinerGUI_ENG,代码行数:7,代码来源:Utils.cs

示例10: Save

        public override void Save(Image i, Stream dest)
        {
            dest.WriteByte(0); // Write No Image ID
            dest.WriteByte(0); // Write No Color-Map
            dest.WriteByte(2); // Write Image Type (Uncompressed- True Color)
            byte[] dat = new byte[5];
            dest.Write(dat, 0, 5); // Write Color-Map Spec

            dest.WriteByte(0);
            dest.WriteByte(0); // Write X-Origin
            dest.WriteByte(0);
            dest.WriteByte(0); // Write Y-Origin
            dat = BitConverter.GetBytes((UInt16)i.Width);
            dest.Write(dat, 0, 2); // Write the Width
            dat = BitConverter.GetBytes((UInt16)i.Height);
            dest.Write(dat, 0, 2); // Write the Height
            dest.WriteByte(32); // Write the Color-Depth

            byte ImageDescriptor = 0;
            ImageDescriptor |= 8; // Set 8-Bit Alpha data.
            ImageDescriptor |= (byte)(1 << 5); // Set Top-Left Image origin
            dest.WriteByte(ImageDescriptor); // Write Image Descriptor Byte

            UInt32 len = (uint)(i.Width * i.Height);
            Pixel p;
            for (int loc = 0; loc < len; loc++) // Write the Image Data.
            {
                p = i.Data[loc];
                dest.WriteByte(p.B);
                dest.WriteByte(p.G);
                dest.WriteByte(p.R);
                dest.WriteByte(p.A);
            }
        }
开发者ID:ChrisJamesSadler,项目名称:Cosmos,代码行数:34,代码来源:TgaSupport.cs

示例11: SendRequest

 protected virtual void SendRequest(Stream outputStream)
 {
     byte[] headerBuffer = this._header.ToByte();
     outputStream.Write(headerBuffer, 0, headerBuffer.Length);
     if (_body != null)
         outputStream.Write(this._body, 0, this._body.Length);
 }
开发者ID:HouZhiHouJue,项目名称:FastDFS.Net,代码行数:7,代码来源:FDFSRequest.cs

示例12: Write

		public void Write(Tag tag, Stream apeStream, Stream tempStream) {
			ByteBuffer tagBuffer = tc.Create(tag);

			if (!TagExists(apeStream)) {
				apeStream.Seek(0, SeekOrigin.End);
				apeStream.Write(tagBuffer.Data, 0, tagBuffer.Capacity);
			} else {
				apeStream.Seek( -32 + 8 , SeekOrigin.End);
			
				//Version
				byte[] b = new byte[4];
				apeStream.Read( b , 0,  b.Length);
				int version = Utils.GetNumber(b, 0, 3);
				if(version != 2000) {
					throw new CannotWriteException("APE Tag other than version 2.0 are not supported");
				}
				
				//Size
				b = new byte[4];
				apeStream.Read( b , 0,  b.Length);
				long oldSize = Utils.GetLongNumber(b, 0, 3) + 32;
				int tagSize = tagBuffer.Capacity;
				
				apeStream.Seek(-oldSize, SeekOrigin.End);
				apeStream.Write(tagBuffer.Data, 0, tagBuffer.Capacity);
					
				if(oldSize > tagSize) {
					//Truncate the file
					apeStream.SetLength(apeStream.Length - (oldSize-tagSize));
				}
			}
		}
开发者ID:emtees,项目名称:old-code,代码行数:32,代码来源:ApeTagWriter.cs

示例13: Write

 public override Stream Write(Stream stream)
 {
     base.Write(stream);
     stream.Write(Topic);
     stream.Write(IsAdd);
     return stream;
 }
开发者ID:rob-blackbourn,项目名称:TopicBus,代码行数:7,代码来源:SubscriptionRequest.cs

示例14: GetCrc32AndCopy

 public int GetCrc32AndCopy(Stream input, Stream output)
 {
     if (input == null)
     {
         throw new ZipException("bad input.", new ArgumentException("The input stream must not be null.", "input"));
     }
     byte[] buffer = new byte[0x2000];
     int readSize = 0x2000;
     this._TotalBytesRead = 0;
     int count = input.Read(buffer, 0, readSize);
     if (output != null)
     {
         output.Write(buffer, 0, count);
     }
     this._TotalBytesRead += count;
     while (count > 0)
     {
         this.SlurpBlock(buffer, 0, count);
         count = input.Read(buffer, 0, readSize);
         if (output != null)
         {
             output.Write(buffer, 0, count);
         }
         this._TotalBytesRead += count;
     }
     return (int) ~this._RunningCrc32Result;
 }
开发者ID:xeno-by,项目名称:datavault,代码行数:27,代码来源:CRC32.cs

示例15: GetCrc32AndCopy

		/// <summary>
		/// Returns the CRC32 for the specified stream, and writes the input into the output stream.
		/// </summary>
		/// <param name="input">The stream over which to calculate the CRC32</param>
		/// <param name="output">The stream into which to deflate the input</param>
		/// <returns>the CRC32 calculation</returns>
		public UInt32 GetCrc32AndCopy(Stream input, Stream output)
		{
			unchecked
			{
				UInt32 crc32Result;
				crc32Result = 0xFFFFFFFF;
				byte[] buffer = new byte[BufferSize];
				int readSize = BufferSize;

				m_TotalBytesRead = 0;
				int count = input.Read(buffer, 0, readSize);
				if (output != null) output.Write(buffer, 0, count);
				m_TotalBytesRead += count;
				while (count > 0)
				{
					for (int i = 0; i < count; i++)
					{
						crc32Result = ((crc32Result) >> 8) ^ m_crc32Table[(buffer[i]) ^ ((crc32Result) & 0x000000FF)];
					}
					count = input.Read(buffer, 0, readSize);
					if (output != null) output.Write(buffer, 0, count);
					m_TotalBytesRead += count;

				}

				return ~crc32Result;
			}
		}
开发者ID:koder05,项目名称:fogel-ba,代码行数:34,代码来源:Crc32.cs


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