/* @file Include/Classes/System/IO/StreamWriter.ab @brief StreamWriterの実装。 */ Namespace System Namespace IO /* @brief ストリームへの書き込みを行うTextWriterの派生。 @date 2008/03/09 @auther Egtra */ Class StreamWriter Inherits TextWriter Public /* @date 2008/03/09 @auther Egtra */ Sub StreamWriter(path As String) init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) End Sub /* @date 2008/03/09 @auther Egtra */ Sub StreamWriter(stream As Stream) init(stream) End Sub /* @brief 基になるストリームを取得する @date 2008/09/02 @auther NoWest */ Function BaseStream () As System.IO.Stream Return s End Function Override Sub Flush() softFlush() s.Flush() End Sub Override Sub WriteLine() Super.WriteLine() softFlush() End Sub Protected Override Sub Dispose(disposing As Boolean) If disposing Then Flush() s.Dispose() End If End Sub Private Sub init(stream As Stream) s = stream buf = New Text.StringBuilder(4096) '暫定。正式版ではUTF-8を標準とする。 e = New Text.Detail.WindowsCodePageEncoding(CP_ACP) End Sub Sub softFlush() Dim buf = Buffer() Dim pws As PCWSTR Dim wcSize = GetWCStr(buf.ToString(), pws) Dim mbMaxSize = e.GetMaxByteCount(wcSize) Dim mbBuf = GC_malloc_atomic(mbMaxSize) As *Byte Dim mbBufSize = e.GetBytes(pws, wcSize, mbBuf, mbMaxSize) s.Write(mbBuf, 0, mbBufSize) End Sub e As Text.Encoding s As System.IO.Stream End Class End Namespace End Namespace