Index: trunk/ab5.0/ablib/src/Classes/System/IO/TextWriter.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/System/IO/TextWriter.ab	(revision 523)
+++ trunk/ab5.0/ablib/src/Classes/System/IO/TextWriter.ab	(revision 653)
@@ -10,4 +10,5 @@
 */
 Class TextWriter
+	Implements System.IDisposable
 Public
 	Virtual Sub ~TextWriter()
@@ -26,153 +27,131 @@
 	End Sub
 
-	Sub TextWriter()
-		newLine = Environment.NewLine
-	End Sub
-
 	Virtual Sub Flush()
 	End Sub
 
-	Abstract Sub Write(s As String)
-	Virtual Sub Write(x As Boolean)
-		Write(Str$(x))
+	'これ以外全てのWrite/WriteLineは、最終的にこのWriteを呼ぶ。
+	Sub Write(x As String)
+		buf.Append(x)
+		If buf.Length >= 4096 Then
+			Flush()
+		End If
 	End Sub
 	
-	Virtual Sub Write(x As Char)
-		Write(Chr$(x))
+	Sub Write(x As Boolean)
+		buf.Append(x)
+	End Sub
+	
+	Sub Write(x As SByte)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As Byte)
-		Write(Str$(x))
-	End Sub
-#ifdef UNICODE
-	Virtual Sub Write(x As SByte)
-		Write(Str$(x))
-	End Sub
-#else
-	Virtual Sub Write(x As Word)
-		Write(Str$(x))
-	End Sub
-#endif
-	Virtual Sub Write(x As Integer)
-		Write(Str$(x))
+	Sub Write(x As Byte)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As DWord)
-		Write(Str$(x))
+	Sub Write(x As Word)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As Long)
-		Write(Str$(x))
+	Sub Write(x As Integer)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As QWord)
-		Write(Str$(x))
+	Sub Write(x As DWord)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As Int64)
-		Write(Str$(x))
+	Sub Write(x As Long)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As Single)
-		Write(Str$(x))
+	Sub Write(x As QWord)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As Double)
-		Write(Str$(x))
+	Sub Write(x As Int64)
+		buf.Append(x)
 	End Sub
 
-	Virtual Sub Write(x As Object)
-		Write(x.ToString)
+	Sub Write(x As Single)
+		buf.Append(x)
+	End Sub
+
+	Sub Write(x As Double)
+		buf.Append(x)
+	End Sub
+
+	Sub Write(x As Object)
+		buf.Append(x)
 	End Sub
 
 	Sub WriteLine()
-		Write(newLine)
+		Write(Environment.NewLine)
 	End Sub
 
-	Sub WriteLine(s As String)
-		Write(s)
+	Sub WriteLine(x As String)
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Boolean)
-		Write(Str$(x))
-		WriteLine()
-	End Sub
-	
-	Sub WriteLine(x As Char)
-		Write(Chr$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Byte)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
-#ifdef UNICODE
+	
 	Sub WriteLine(x As SByte)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
-#else
+
 	Sub WriteLine(x As Word)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
-#endif
+
 	Sub WriteLine(x As Integer)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As DWord)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Long)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As QWord)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Int64)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Single)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Double)
-		Write(Str$(x))
+		Write(x)
 		WriteLine()
 	End Sub
 
 	Sub WriteLine(x As Object)
-		Write(x.ToString)
+		Write(x)
 		WriteLine()
 	End Sub
-
-	/*
-	@brief 改行文字の設定
-	@date 2007/03/05
-	@auther Egtra
-	*/
-	Sub NewLine(n As String)
-		newLine = n
-	End Sub
-	/*
-	@brief 改行文字の取得
-	@date 2007/03/05
-	@auther Egtra
-	*/
-	Function NewLine() As String
-	End Function
 
 	Static Function Synchronized(writer As TextWriter) As TextWriter
@@ -180,10 +159,30 @@
 		Return writer
 	End Function
+
 Protected
+	Sub TextWriter()
+		buf = New Text.StringBuilder
+	End Sub
+
+	Sub TextWriter(buffer As Text.StringBuilder)
+		If ActiveBasic.IsNothing(buffer) Then
+			Throw New ArgumentNullException("buffer")
+		End If
+		buf = buffer
+	End Sub
+
+	Function Buffer() As Text.StringBuilder
+		Buffer = buf
+	End Function
+
 	Virtual Sub Dispose(disposing As Boolean)
+		If disposing Then
+			Flush()
+			buf = Nothing
+		End If
 	End Sub
 
 Private
-	newLine As String
+	buf As Text.StringBuilder
 End Class
 
