source: trunk/Include/Classes/System/IO/StreamWriter.ab@ 472

Last change on this file since 472 was 470, checked in by OverTaker, 17 years ago

StreamWriterで2048バイト単位でしか書き込めないバグを修正。

File size: 1.8 KB
Line 
1Namespace System
2Namespace IO
3
4
5Class StreamWriter
6 Inherits TextWriter
7Public
8 /*
9 @date 2008/02/25
10 @auther Egtra
11 */
12 Sub StreamWriter(path As String)
13 init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
14 End Sub
15
16 /*
17 @date 2008/02/25
18 @auther Egtra
19 */
20 Sub StreamWriter(stream As Stream)
21 init(stream)
22 End Sub
23
24 Override Sub Write(str As String)
25 buf.Append(str)
26 Dim len = buf.Length
27 If len >= 2048 Then
28 s.Write(StrPtr(buf) As *Byte, 0, len)
29 buf.Length = 0
30 End If
31 End Sub
32
33 Override Sub Write(x As Boolean)
34 buf.Append(x)
35 End Sub
36
37 Override Sub Write(x As Char)
38 buf.Append(x)
39 End Sub
40
41 Override Sub Write(x As Byte)
42 buf.Append(x)
43 End Sub
44#ifdef UNICODE
45 Override Sub Write(x As SByte)
46 buf.Append(x)
47 End Sub
48#else
49 Override Sub Write(x As Word)
50 buf.Append(x)
51 End Sub
52#endif
53 Override Sub Write(x As Integer)
54 buf.Append(x)
55 End Sub
56
57 Override Sub Write(x As DWord)
58 buf.Append(x)
59 End Sub
60
61 Override Sub Write(x As Long)
62 buf.Append(x)
63 End Sub
64
65 Override Sub Write(x As QWord)
66 buf.Append(x)
67 End Sub
68
69 Override Sub Write(x As Int64)
70 buf.Append(x)
71 End Sub
72
73 Override Sub Write(x As Single)
74 buf.Append(x)
75 End Sub
76
77 Override Sub Write(x As Double)
78 buf.Append(x)
79 End Sub
80
81 Override Sub Write(x As Object)
82 Write(x.ToString)
83 End Sub
84
85Protected
86 Override Sub Dispose(disposing As Boolean)
87 If disposing Then
88 Dim len = buf.Length
89 If len > 0 Then
90 s.Write(StrPtr(buf) As *Byte, 0, len)
91 End If
92 s.Dispose()
93 End If
94 End Sub
95
96Private
97 Sub init(stream As Stream)
98 s = stream
99 buf = New System.Text.StringBuilder(4096)
100 End Sub
101
102 buf As Text.StringBuilder
103 s As System.IO.Stream
104End Class
105
106
107End Namespace
108End Namespace
Note: See TracBrowser for help on using the repository browser.