Last change
on this file since 676 was 673, checked in by イグトランス (egtra), 16 years ago |
Encoder/Decoderを排除した実装(UTF8Encodingは修正していません)。
|
File size:
1.5 KB
|
Line | |
---|
1 | /*
|
---|
2 | @file Include/Classes/System/IO/StreamWriter.ab
|
---|
3 | @brief StreamWriterの実装。
|
---|
4 | */
|
---|
5 |
|
---|
6 | Namespace System
|
---|
7 | Namespace IO
|
---|
8 |
|
---|
9 | /*
|
---|
10 | @brief ストリームへの書き込みを行うTextWriterの派生。
|
---|
11 | @date 2008/03/09
|
---|
12 | @auther Egtra
|
---|
13 | */
|
---|
14 | Class StreamWriter
|
---|
15 | Inherits TextWriter
|
---|
16 | Public
|
---|
17 | /*
|
---|
18 | @date 2008/03/09
|
---|
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 | /*
|
---|
26 | @date 2008/03/09
|
---|
27 | @auther Egtra
|
---|
28 | */
|
---|
29 | Sub StreamWriter(stream As Stream)
|
---|
30 | init(stream)
|
---|
31 | End Sub
|
---|
32 |
|
---|
33 | /*
|
---|
34 | @brief 基になるストリームを取得する
|
---|
35 | @date 2008/09/02
|
---|
36 | @auther NoWest
|
---|
37 | */
|
---|
38 | Function BaseStream () As System.IO.Stream
|
---|
39 | Return s
|
---|
40 | End Function
|
---|
41 |
|
---|
42 | Override Sub Flush()
|
---|
43 | softFlush()
|
---|
44 | s.Flush()
|
---|
45 | End Sub
|
---|
46 |
|
---|
47 | Override Sub WriteLine()
|
---|
48 | Super.WriteLine()
|
---|
49 | softFlush()
|
---|
50 | End Sub
|
---|
51 |
|
---|
52 | Protected
|
---|
53 | Override Sub Dispose(disposing As Boolean)
|
---|
54 | If disposing Then
|
---|
55 | Flush()
|
---|
56 | s.Dispose()
|
---|
57 | End If
|
---|
58 | End Sub
|
---|
59 |
|
---|
60 | Private
|
---|
61 | Sub init(stream As Stream)
|
---|
62 | s = stream
|
---|
63 | buf = New Text.StringBuilder(4096)
|
---|
64 | '暫定。正式版ではUTF-8を標準とする。
|
---|
65 | e = New Text.Detail.WindowsCodePageEncoding(CP_ACP)
|
---|
66 | End Sub
|
---|
67 |
|
---|
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)
|
---|
76 | End Sub
|
---|
77 |
|
---|
78 | e As Text.Encoding
|
---|
79 | s As System.IO.Stream
|
---|
80 | End Class
|
---|
81 |
|
---|
82 | End Namespace
|
---|
83 | End Namespace
|
---|
Note:
See
TracBrowser
for help on using the repository browser.