Changeset 653 for trunk/ab5.0/ablib/src/Classes/System/IO
- Timestamp:
- Nov 3, 2008, 11:42:22 PM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src/Classes/System/IO
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/IO/BinaryReader.ab
r553 r653 1 Name Space System2 Name Space IO1 Namespace System 2 Namespace IO 3 3 4 4 Class BinaryReader … … 13 13 Sub BinaryReader(input As Stream) 14 14 stream = input 15 enc = New System.Text.UTF8Encoding()15 ' enc = New System.Text.UTF8Encoding() 16 16 End Sub 17 17 /*! -
trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab
r627 r653 41 41 42 42 Override Sub Flush() 43 Dim len = buf.Length 44 If len > 0 Then 45 s.Write(StrPtr(buf) As *Byte, 0, len) 46 buf.Length = 0 47 End If 48 End Sub 49 50 Override Sub Write(str As String) 51 buf.Append(str) 52 Dim len = buf.Length 53 If len >= 2048 Then 54 s.Write(StrPtr(buf) As *Byte, 0, len) 55 buf.Length = 0 56 End If 57 End Sub 58 59 Override Sub Write(x As Boolean) 60 buf.Append(x) 61 End Sub 62 63 Override Sub Write(x As Char) 64 buf.Append(x) 65 End Sub 66 67 Override Sub Write(x As Byte) 68 buf.Append(x) 69 End Sub 70 #ifdef UNICODE 71 Override Sub Write(x As SByte) 72 buf.Append(x) 73 End Sub 74 #else 75 Override Sub Write(x As Word) 76 buf.Append(x) 77 End Sub 78 #endif 79 Override Sub Write(x As Integer) 80 buf.Append(x) 81 End Sub 82 83 Override Sub Write(x As DWord) 84 buf.Append(x) 85 End Sub 86 87 Override Sub Write(x As Long) 88 buf.Append(x) 89 End Sub 90 91 Override Sub Write(x As QWord) 92 buf.Append(x) 93 End Sub 94 95 Override Sub Write(x As Int64) 96 buf.Append(x) 97 End Sub 98 99 Override Sub Write(x As Single) 100 buf.Append(x) 101 End Sub 102 103 Override Sub Write(x As Double) 104 buf.Append(x) 105 End Sub 106 107 Override Sub Write(x As Object) 108 Write(x.ToString) 43 Dim buf = Buffer() 44 Dim pws As PCWSTR 45 Dim size = GetWCStr(buf.ToString(), pws) 46 Dim pwsEnd = VarPtr(pws[size]) 47 Dim charConverted As Long 48 Dim byteBuf[4095] As Byte 49 Dim byteSize As Long 50 Dim completed As Boolean 51 Do 52 Dim converted As Long 53 encoder.Convert(pws, size, byteBuf, Len(byteBuf), False, charConverted, byteSize, completed) 54 s.Write(byteBuf, 0, byteSize) 55 pws = VarPtr(pws[charConverted]) 56 size -= charConverted 57 Loop Until pws = pwsEnd 58 buf.Length = 0 109 59 End Sub 110 60 … … 112 62 Override Sub Dispose(disposing As Boolean) 113 63 If disposing Then 114 Dim len = buf.Length 115 If len > 0 Then 116 s.Write(StrPtr(buf) As *Byte, 0, len) 117 End If 64 Flush() 65 flushLast() 118 66 s.Dispose() 119 67 End If … … 123 71 Sub init(stream As Stream) 124 72 s = stream 125 buf = New System.Text.StringBuilder(4096) 73 buf = New Text.StringBuilder(4096) 74 '暫定。正式版ではUTF-8を標準とする。 75 encoding = New Text.Detail.WindowsCodePageEncoding(CP_ACP) 76 encoder = encoding.GetEncoder() 126 77 End Sub 127 78 128 buf As Text.StringBuilder 79 Sub flushLast() 80 Dim charConverted As Long 81 Dim byteBuf[63] As Byte 82 Dim byteSize As Long 83 Dim completed As Boolean 84 Do 85 encoder.Convert(0, 0, byteBuf, Len(byteBuf), False, charConverted, byteSize, completed) 86 s.Write(byteBuf, 0, byteSize) 87 Loop Until completed 88 End Sub 89 90 encoding As Text.Encoding 91 encoder As Text.Encoder 129 92 s As System.IO.Stream 130 93 End Class -
trunk/ab5.0/ablib/src/Classes/System/IO/TextWriter.ab
r523 r653 10 10 */ 11 11 Class TextWriter 12 Implements System.IDisposable 12 13 Public 13 14 Virtual Sub ~TextWriter() … … 26 27 End Sub 27 28 28 Sub TextWriter()29 newLine = Environment.NewLine30 End Sub31 32 29 Virtual Sub Flush() 33 30 End Sub 34 31 35 Abstract Sub Write(s As String) 36 Virtual Sub Write(x As Boolean) 37 Write(Str$(x)) 32 'これ以外全てのWrite/WriteLineは、最終的にこのWriteを呼ぶ。 33 Sub Write(x As String) 34 buf.Append(x) 35 If buf.Length >= 4096 Then 36 Flush() 37 End If 38 38 End Sub 39 39 40 Virtual Sub Write(x As Char) 41 Write(Chr$(x)) 40 Sub Write(x As Boolean) 41 buf.Append(x) 42 End Sub 43 44 Sub Write(x As SByte) 45 buf.Append(x) 42 46 End Sub 43 47 44 Virtual Sub Write(x As Byte) 45 Write(Str$(x)) 46 End Sub 47 #ifdef UNICODE 48 Virtual Sub Write(x As SByte) 49 Write(Str$(x)) 50 End Sub 51 #else 52 Virtual Sub Write(x As Word) 53 Write(Str$(x)) 54 End Sub 55 #endif 56 Virtual Sub Write(x As Integer) 57 Write(Str$(x)) 48 Sub Write(x As Byte) 49 buf.Append(x) 58 50 End Sub 59 51 60 Virtual Sub Write(x As DWord)61 Write(Str$(x))52 Sub Write(x As Word) 53 buf.Append(x) 62 54 End Sub 63 55 64 Virtual Sub Write(x As Long)65 Write(Str$(x))56 Sub Write(x As Integer) 57 buf.Append(x) 66 58 End Sub 67 59 68 Virtual Sub Write(x As QWord)69 Write(Str$(x))60 Sub Write(x As DWord) 61 buf.Append(x) 70 62 End Sub 71 63 72 Virtual Sub Write(x As Int64)73 Write(Str$(x))64 Sub Write(x As Long) 65 buf.Append(x) 74 66 End Sub 75 67 76 Virtual Sub Write(x As Single)77 Write(Str$(x))68 Sub Write(x As QWord) 69 buf.Append(x) 78 70 End Sub 79 71 80 Virtual Sub Write(x As Double)81 Write(Str$(x))72 Sub Write(x As Int64) 73 buf.Append(x) 82 74 End Sub 83 75 84 Virtual Sub Write(x As Object) 85 Write(x.ToString) 76 Sub Write(x As Single) 77 buf.Append(x) 78 End Sub 79 80 Sub Write(x As Double) 81 buf.Append(x) 82 End Sub 83 84 Sub Write(x As Object) 85 buf.Append(x) 86 86 End Sub 87 87 88 88 Sub WriteLine() 89 Write( newLine)89 Write(Environment.NewLine) 90 90 End Sub 91 91 92 Sub WriteLine( sAs String)93 Write( s)92 Sub WriteLine(x As String) 93 Write(x) 94 94 WriteLine() 95 95 End Sub 96 96 97 97 Sub WriteLine(x As Boolean) 98 Write(Str$(x)) 99 WriteLine() 100 End Sub 101 102 Sub WriteLine(x As Char) 103 Write(Chr$(x)) 98 Write(x) 104 99 WriteLine() 105 100 End Sub 106 101 107 102 Sub WriteLine(x As Byte) 108 Write( Str$(x))103 Write(x) 109 104 WriteLine() 110 105 End Sub 111 #ifdef UNICODE 106 112 107 Sub WriteLine(x As SByte) 113 Write( Str$(x))108 Write(x) 114 109 WriteLine() 115 110 End Sub 116 #else 111 117 112 Sub WriteLine(x As Word) 118 Write( Str$(x))113 Write(x) 119 114 WriteLine() 120 115 End Sub 121 #endif 116 122 117 Sub WriteLine(x As Integer) 123 Write( Str$(x))118 Write(x) 124 119 WriteLine() 125 120 End Sub 126 121 127 122 Sub WriteLine(x As DWord) 128 Write( Str$(x))123 Write(x) 129 124 WriteLine() 130 125 End Sub 131 126 132 127 Sub WriteLine(x As Long) 133 Write( Str$(x))128 Write(x) 134 129 WriteLine() 135 130 End Sub 136 131 137 132 Sub WriteLine(x As QWord) 138 Write( Str$(x))133 Write(x) 139 134 WriteLine() 140 135 End Sub 141 136 142 137 Sub WriteLine(x As Int64) 143 Write( Str$(x))138 Write(x) 144 139 WriteLine() 145 140 End Sub 146 141 147 142 Sub WriteLine(x As Single) 148 Write( Str$(x))143 Write(x) 149 144 WriteLine() 150 145 End Sub 151 146 152 147 Sub WriteLine(x As Double) 153 Write( Str$(x))148 Write(x) 154 149 WriteLine() 155 150 End Sub 156 151 157 152 Sub WriteLine(x As Object) 158 Write(x .ToString)153 Write(x) 159 154 WriteLine() 160 155 End Sub 161 162 /*163 @brief 改行文字の設定164 @date 2007/03/05165 @auther Egtra166 */167 Sub NewLine(n As String)168 newLine = n169 End Sub170 /*171 @brief 改行文字の取得172 @date 2007/03/05173 @auther Egtra174 */175 Function NewLine() As String176 End Function177 156 178 157 Static Function Synchronized(writer As TextWriter) As TextWriter … … 180 159 Return writer 181 160 End Function 161 182 162 Protected 163 Sub TextWriter() 164 buf = New Text.StringBuilder 165 End Sub 166 167 Sub TextWriter(buffer As Text.StringBuilder) 168 If ActiveBasic.IsNothing(buffer) Then 169 Throw New ArgumentNullException("buffer") 170 End If 171 buf = buffer 172 End Sub 173 174 Function Buffer() As Text.StringBuilder 175 Buffer = buf 176 End Function 177 183 178 Virtual Sub Dispose(disposing As Boolean) 179 If disposing Then 180 Flush() 181 buf = Nothing 182 End If 184 183 End Sub 185 184 186 185 Private 187 newLine As String186 buf As Text.StringBuilder 188 187 End Class 189 188
Note:
See TracChangeset
for help on using the changeset viewer.