C# IOException.Equals的代码示例
通过代码示例来学习C# IOException.Equals方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
IOException.Equals是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的IOException.Equals() 已经帮大家高亮显示了,大家可以重点学习IOException.Equals() 方法的写法,从而快速掌握该方法的应用。
IOException.Equals的代码示例1 - 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()方法中,IOException的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
IOException.Equals的代码示例2 - VerifyTransferAsync()
using System.IO; ///
/// Verify a file transfer /// /// /// /// ////// protected async Task VerifyTransferAsync(string localPath, string remotePath, CancellationToken token = default(CancellationToken)) { // verify args if (localPath.IsBlank()) { throw new ArgumentException("Required parameter is null or blank.", nameof(localPath)); } if (remotePath.IsBlank()) { throw new ArgumentException("Required parameter is null or blank.", nameof(remotePath)); } FtpVerifyMethod verifyMethod = Config.VerifyMethod; try { //fallback to size if only checksum is set and the server does not support hashing. if (verifyMethod == FtpVerifyMethod.Checksum && !SupportsChecksum()) { Log(FtpTraceLevel.Info, "Source server does not support any common hashing algorithm"); Log(FtpTraceLevel.Info, "Falling back to file size comparison"); verifyMethod = FtpVerifyMethod.Size; } //compare size if (verifyMethod.HasFlag(FtpVerifyMethod.Size)) { var localSize = await FtpFileStream.GetFileSizeAsync(localPath, false, token); var remoteSize = await GetFileSize(remotePath, -1, token); if (localSize != remoteSize) { return false; } } //compare date modified if (verifyMethod.HasFlag(FtpVerifyMethod.Date)) { var localDate = await FtpFileStream.GetFileDateModifiedUtcAsync(localPath, token); var remoteDate = await GetModifiedTime(remotePath, token); if (!localDate.Equals(remoteDate)) { return false; } } //compare hash if (verifyMethod.HasFlag(FtpVerifyMethod.Checksum) && SupportsChecksum()) { FtpHash hash = await GetChecksum(remotePath, FtpHashAlgorithm.NONE, token); if (!hash.IsValid) { return false; } return hash.Verify(localPath); } // check was successful return true; } catch (IOException ex) { LogWithPrefix(FtpTraceLevel.Warn, "Failed to verify file " + localPath, ex); return false; } }
开发者ID:robinrodricks,项目名称:FluentFTP,代码行数:66,代码来源:VerifyTransfer.cs
在VerifyTransferAsync()方法中,IOException的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
IOException.Equals的代码示例3 - GetFile()
using System.IO; /** * * @param sampleFileName the name of the test file * @return * @throws RuntimeException if the file was not found */ public FileStream GetFile(String sampleFileName) { string path=_resolvedDataDir+sampleFileName; if (!File.Exists(path)) { throw new Exception("Sample file '" + sampleFileName + "' not found in data dir '" + _resolvedDataDir + "'"); } //try //{ // if (sampleFileName.Length > 0 && !sampleFileName.Equals(f.getCanonicalFile().getName())) // { // throw new RuntimeException("File name is case-sensitive: requested '" + sampleFileName // + "' but actual file is '" + f.getCanonicalFile().getName() + "'"); // } //} //catch (IOException e) //{ // throw new RuntimeException(e); //} return new FileStream(path,FileMode.OpenOrCreate,FileAccess.ReadWrite); }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:30,代码来源:POIDataSamples.cs
在GetFile()方法中,IOException的代码示例类中的Equals的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的IOException.Equals方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。