C# Stream.CopyTo的代码示例
通过代码示例来学习C# Stream.CopyTo方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
Stream.CopyTo是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Stream.CopyTo() 已经帮大家高亮显示了,大家可以重点学习Stream.CopyTo() 方法的写法,从而快速掌握该方法的应用。
Stream.CopyTo的代码示例1 - GetIndexHash()
using System.IO; private byte[] GetIndexHash() { if (this.shouldHashIndex) { using (Stream fileStream = new FileStream(this.indexLockPath, FileMode.Open, FileAccess.Read, FileShare.Write)) using (HashingStream hasher = new HashingStream(fileStream)) { hasher.CopyTo(Stream.Null); return hasher.Hash; } } return new byte[20]; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:16,代码来源:GitIndexGenerator.cs
在GetIndexHash()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例2 - WriteLooseObject()
using System.IO; public virtual string WriteLooseObject(Stream responseStream, string sha, bool overwriteExistingObject, byte[] bufToCopyWith) { try { LooseObjectToWrite toWrite = this.GetLooseObjectDestination(sha); if (this.checkData) { try { using (Stream fileStream = this.OpenTempLooseObjectStream(toWrite.TempFile)) using (SideChannelStream sideChannel = new SideChannelStream(from: responseStream, to: fileStream)) using (InflaterInputStream inflate = new InflaterInputStream(sideChannel)) using (HashingStream hashing = new HashingStream(inflate)) using (NoOpStream devNull = new NoOpStream()) { hashing.CopyTo(devNull); string actualSha = SHA1Util.HexStringFromBytes(hashing.Hash); if (!sha.Equals(actualSha, StringComparison.OrdinalIgnoreCase)) { string message = $"Requested object with hash {sha} but received object with hash {actualSha}."; message += $"\nFind the incorrect data at '{toWrite.TempFile}'"; this.Tracer.RelatedError(message); throw new SecurityException(message); } } } catch (SharpZipBaseException) { string message = $"Requested object with hash {sha} but received data that failed decompression."; message += $"\nFind the incorrect data at '{toWrite.TempFile}'"; this.Tracer.RelatedError(message); throw new RetryableException(message); } } else { using (Stream fileStream = this.OpenTempLooseObjectStream(toWrite.TempFile)) { StreamUtil.CopyToWithBuffer(responseStream, fileStream, bufToCopyWith); fileStream.Flush(); } } this.FinalizeTempFile(sha, toWrite, overwriteExistingObject); return toWrite.ActualFile; } catch (IOException e) { throw new RetryableException("IOException while writing loose object. See inner exception for details.", e); } catch (UnauthorizedAccessException e) { throw new RetryableException("UnauthorizedAccessException while writing loose object. See inner exception for details.", e); } catch (Win32Exception e) { throw new RetryableException("Win32Exception while writing loose object. See inner exception for details.", e); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:65,代码来源:GitObjects.cs
在WriteLooseObject()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例3 - SignIndex()
using System.IO; private void SignIndex() { using (ITracer activity = this.tracer.StartActivity("SignIndex", EventLevel.Informational, Keywords.Telemetry, metadata: null)) { using (FileStream fs = File.Open(this.indexPath, FileMode.Open, FileAccess.ReadWrite)) { // Truncate the old hash off. The Index class is expected to preserve any existing hash. fs.SetLength(fs.Length - 20); using (HashingStream hashStream = new HashingStream(fs)) { fs.Position = 0; hashStream.CopyTo(Stream.Null); byte[] hash = hashStream.Hash; // The fs pointer is now where the old hash used to be. Perfect. :) fs.Write(hash, 0, hash.Length); } } } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:22,代码来源:Index.cs
在SignIndex()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例4 - StartProcess()
using System.IO; private static string StartProcess(Process executingProcess, Stream inputStream = null) { executingProcess.Start(); if (inputStream != null) { inputStream.CopyTo(executingProcess.StandardInput.BaseStream); } if (executingProcess.StartInfo.RedirectStandardError) { executingProcess.BeginErrorReadLine(); } string output = string.Empty; if (executingProcess.StartInfo.RedirectStandardOutput) { output = executingProcess.StandardOutput.ReadToEnd(); } executingProcess.WaitForExit(); return output; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:26,代码来源:ProcessHelper.cs
在StartProcess()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例5 - CopyToWithBuffer()
using System.IO; ///
/// Copies all bytes from the source stream to the destination stream. This is an exact copy /// of Stream.CopyTo(), but can uses the supplied buffer instead of allocating a new one. /// ////// As of .NET 4.6, each call to Stream.CopyTo() allocates a new 80K byte[] buffer, which /// consumes many more resources than reusing one we already have if the scenario allows it. /// /// Source stream to copy from /// Destination stream to copy to /// /// Shared buffer to use. If null, we allocate one with the same size .NET would otherwise use. /// public static void CopyToWithBuffer(Stream source, Stream destination, byte[] buffer = null) { buffer = buffer ?? new byte[DefaultCopyBufferSize]; int read; while (true) { try { read = source.Read(buffer, 0, buffer.Length); } catch (Exception ex) { // All exceptions potentially from network should be retried throw new RetryableException("Exception while reading stream. See inner exception for details.", ex); } if (read == 0) { break; } destination.Write(buffer, 0, read); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:39,代码来源:StreamUtil.cs
在CopyToWithBuffer()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例6 - Read()
using System.IO; public override Stream Read() { // Act like a file and have a UTF8 BOM. var preamble = Encoding.UTF8.GetPreamble(); var contentBytes = Encoding.UTF8.GetBytes(Content); var buffer = new byte[preamble.Length + contentBytes.Length]; preamble.CopyTo(buffer, 0); contentBytes.CopyTo(buffer, preamble.Length); var stream = new MemoryStream(buffer); return stream; }
开发者ID:aspnet,项目名称:Razor,代码行数:15,代码来源:TestRazorProjectItem.cs
在Read()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例7 - compress()
using System.IO; private static MemoryStream compress(this Stream stream) { var output = new MemoryStream(); if (stream.Length == 0) return output; stream.Position = 0; using (var ds = new DeflateStream(output, CompressionMode.Compress, true)) { stream.CopyTo(ds, 1024); ds.Close(); // BFINAL set to 1. output.Write(_last, 0, 1); output.Position = 0; return output; } }
开发者ID:ntminer,项目名称:NtMiner,代码行数:17,代码来源:Ext.cs
在compress()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Stream.CopyTo的代码示例8 - ExtractToFile()
using System.IO; private static void ExtractToFile(ZipArchiveEntry source, string destinationFileName, bool overwrite) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (destinationFileName == null) { throw new ArgumentNullException(nameof(destinationFileName)); } FileMode fMode = overwrite ? FileMode.Create : FileMode.CreateNew; using (FileStream fs = new FileStream(destinationFileName, fMode, FileAccess.Write, FileShare.None, bufferSize: 0x1000, useAsync: false)) using (Stream es = source.Open()) using (MaxLengthStream maxLengthStream = new MaxLengthStream(es, source.Length)) { maxLengthStream.CopyTo(fs); } File.SetLastWriteTime(destinationFileName, source.LastWriteTime.DateTime); }
开发者ID:ShareX,项目名称:ShareX,代码行数:25,代码来源:ZipManager.cs
在ExtractToFile()方法中,Stream的代码示例类中的CopyTo的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的Stream.CopyTo方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。