Last change
on this file since 673 was 673, checked in by イグトランス (egtra), 15 years ago |
Encoder/Decoderを排除した実装(UTF8Encodingは修正していません)。
|
File size:
1.5 KB
|
Rev | Line | |
---|
[473] | 1 | /*
|
---|
| 2 | @file Include/Classes/System/IO/StreamWriter.ab
|
---|
| 3 | @brief StreamWriterの実装。
|
---|
| 4 | */
|
---|
| 5 |
|
---|
[271] | 6 | Namespace System
|
---|
| 7 | Namespace IO
|
---|
[473] | 8 |
|
---|
| 9 | /*
|
---|
[476] | 10 | @brief ストリームへの書き込みを行うTextWriterの派生。
|
---|
[473] | 11 | @date 2008/03/09
|
---|
| 12 | @auther Egtra
|
---|
| 13 | */
|
---|
[105] | 14 | Class StreamWriter
|
---|
[468] | 15 | Inherits TextWriter
|
---|
| 16 | Public
|
---|
| 17 | /*
|
---|
[473] | 18 | @date 2008/03/09
|
---|
[468] | 19 | @auther Egtra
|
---|
| 20 | */
|
---|
| 21 | Sub StreamWriter(path As String)
|
---|
| 22 | init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
|
---|
| 23 | End Sub
|
---|
| 24 |
|
---|
| 25 | /*
|
---|
[473] | 26 | @date 2008/03/09
|
---|
[468] | 27 | @auther Egtra
|
---|
| 28 | */
|
---|
| 29 | Sub StreamWriter(stream As Stream)
|
---|
| 30 | init(stream)
|
---|
| 31 | End Sub
|
---|
| 32 |
|
---|
[622] | 33 | /*
|
---|
| 34 | @brief 基になるストリームを取得する
|
---|
| 35 | @date 2008/09/02
|
---|
| 36 | @auther NoWest
|
---|
| 37 | */
|
---|
[627] | 38 | Function BaseStream () As System.IO.Stream
|
---|
[622] | 39 | Return s
|
---|
| 40 | End Function
|
---|
| 41 |
|
---|
[473] | 42 | Override Sub Flush()
|
---|
[673] | 43 | softFlush()
|
---|
| 44 | s.Flush()
|
---|
[473] | 45 | End Sub
|
---|
| 46 |
|
---|
[673] | 47 | Override Sub WriteLine()
|
---|
| 48 | Super.WriteLine()
|
---|
| 49 | softFlush()
|
---|
| 50 | End Sub
|
---|
| 51 |
|
---|
[468] | 52 | Protected
|
---|
| 53 | Override Sub Dispose(disposing As Boolean)
|
---|
| 54 | If disposing Then
|
---|
[653] | 55 | Flush()
|
---|
[468] | 56 | s.Dispose()
|
---|
| 57 | End If
|
---|
| 58 | End Sub
|
---|
| 59 |
|
---|
| 60 | Private
|
---|
| 61 | Sub init(stream As Stream)
|
---|
| 62 | s = stream
|
---|
[653] | 63 | buf = New Text.StringBuilder(4096)
|
---|
| 64 | '暫定。正式版ではUTF-8を標準とする。
|
---|
[673] | 65 | e = New Text.Detail.WindowsCodePageEncoding(CP_ACP)
|
---|
[468] | 66 | End Sub
|
---|
| 67 |
|
---|
[673] | 68 | Sub softFlush()
|
---|
| 69 | Dim buf = Buffer()
|
---|
| 70 | Dim pws As PCWSTR
|
---|
| 71 | Dim wcSize = GetWCStr(buf.ToString(), pws)
|
---|
| 72 | Dim mbMaxSize = e.GetMaxByteCount(wcSize)
|
---|
| 73 | Dim mbBuf = GC_malloc_atomic(mbMaxSize) As *Byte
|
---|
| 74 | Dim mbBufSize = e.GetBytes(pws, wcSize, mbBuf, mbMaxSize)
|
---|
| 75 | s.Write(mbBuf, 0, mbBufSize)
|
---|
[653] | 76 | End Sub
|
---|
| 77 |
|
---|
[673] | 78 | e As Text.Encoding
|
---|
[468] | 79 | s As System.IO.Stream
|
---|
[271] | 80 | End Class
|
---|
| 81 |
|
---|
| 82 | End Namespace
|
---|
| 83 | End Namespace
|
---|
Note:
See
TracBrowser
for help on using the repository browser.