C# BufferedStream.Close的代码示例
通过代码示例来学习C# BufferedStream.Close方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
BufferedStream.Close是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的BufferedStream.Close() 已经帮大家高亮显示了,大家可以重点学习BufferedStream.Close() 方法的写法,从而快速掌握该方法的应用。
BufferedStream.Close的代码示例1 - DisposeAsyncCore()
using System.IO; #endif ///
/// Disconnects from server, actually /// #if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER protected async ValueTask DisposeAsyncCore() { #else protected async Task DisposeAsyncCore() { #endif if (IsDisposed) { return; } if (Client != null) { string connText = this.IsControlConnection ? "control" : "data"; ((IInternalFtpClient)Client).LogStatus(FtpTraceLevel.Verbose, "Disposing(async) FtpSocketStream(" + connText + " connection of " + Client.ClientType + ")"); } if (m_customStream != null) { try { m_customStream.Dispose(); // Async not supported by custom stream interface } catch { } m_customStream = null; } if (m_sslStream != null) { try { m_sslStream.Close(); // This blocks. It should be recorded in FtpSslStream.cs to be sort of async #if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER await m_sslStream.DisposeAsync(); #else ((IInternalFtpClient)Client).LogStatus(FtpTraceLevel.Verbose, "Disposing(sync) FtpSslStream of FtpSocketStream"); m_sslStream.Dispose(); // Async dispose not supported in this .NET? #endif } catch { } m_sslStream = null; } if (m_bufStream != null) { try { #if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER await m_bufStream.DisposeAsync(); #else ((IInternalFtpClient)Client).LogStatus(FtpTraceLevel.Verbose, "Disposing(sync) BufferedStream of FtpSocketStream"); m_bufStream.Dispose(); // Async dispose not supported in this .NET? #endif } catch { } m_bufStream = null; } if (m_netStream != null) { try { #if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER await m_netStream.DisposeAsync(); #else ((IInternalFtpClient)Client).LogStatus(FtpTraceLevel.Verbose, "Disposing(sync) NetworkStream of FtpSocketStream"); m_netStream.Dispose(); // Async dispose not supported in this .NET? #endif } catch { } m_netStream = null; } DisposeSocket(); base.Dispose(true); if (Client.Status.DaemonRunning) { if (!this.IsControlConnection) { Client.Status.DaemonCmdMode = true; } } IsDisposed = true; }
开发者ID:robinrodricks,项目名称:FluentFTP,代码行数:84,代码来源:FtpSocketStream.cs
在DisposeAsyncCore()方法中,BufferedStream的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
BufferedStream.Close的代码示例2 - Store()
using System.IO; private int Store(Stream inStream) { int bigBlockSize = POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE; //BufferedStream bis = new BufferedStream(stream, bigBlockSize + 1); //bis.mark(bigBlockSize); //// Buffer the contents into memory. This is a bit icky... //// TODO Replace with a buffer up to the mini stream size, then streaming write //byte[] contents; //if (stream is MemoryStream) //{ // MemoryStream bais = (MemoryStream)stream; // contents = new byte[bais.Length]; // bais.Read(contents, 0, contents.Length); //} //else //{ // MemoryStream baos = new MemoryStream(); // IOUtils.Copy(stream, baos); // contents = baos.ToArray(); //} // Do we need to store as a mini stream or a full one? if (inStream.Length < bigBlockSize) { _stream = new NPOIFSStream(_filesystem.GetMiniStore()); _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize(); } else { _stream = new NPOIFSStream(_filesystem); _block_size = _filesystem.GetBlockStoreBlockSize(); } // start from the beginning //bis.Seek(0, SeekOrigin.Begin); // Store it Stream outStream = _stream.GetOutputStream(); byte[] buf = new byte[1024]; int length = 0; //for (int readBytes; (readBytes = bis.Read(buf, 0, buf.Length)) != 0; length += readBytes) //{ // outStream.Write(buf, 0, readBytes); //} for (int readBytes = 0; ; ) { readBytes = inStream.Read(buf, 0, buf.Length); if (readBytes <= 0) break; length += readBytes; outStream.Write(buf, 0, readBytes); } outStream.Close(); return length; }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:60,代码来源:NPOIFSDocument.cs
在Store()方法中,BufferedStream的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的BufferedStream.Close方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。