テキストファイル書き込み用クラス

これまでC# で作成してきた「SourceToHTML」を、VJ# に焼きなおしてみます。

Writer.jsl


package SourceToHtml;

//*******************************************************************************************************
// テキストファイル 書き込み用クラス
//*******************************************************************************************************
public class Writer
{
private static final char NEWLINE = '\n';

private System.IO.StreamWriter textWriter;
private boolean IsOpen = false;
private String fileName = "";
private String writeBuffer = "";
//---------------------------------------------------------------------------------------------------
// 初期化
//---------------------------------------------------------------------------------------------------
public Writer(String fileName)
{
this.fileName = fileName;
}
//---------------------------------------------------------------------------------------------------
// 終了
//---------------------------------------------------------------------------------------------------
protected void Finalize()
{
Close();
}
public void Close()
{
//OPENしてたら
if (IsOpen)
{
//書き込み用バッファに何か残っていたら
if (writeBuffer != "")
{
//書き込み用バッファの内容を書き込み、バッファをクリアする
putLine();
}

//CLOSEする
textWriter.Close();
textWriter = null;
IsOpen = false;
}
}
//---------------------------------------------------------------------------------------------------
// 出力ファイルに文字列を書く
//---------------------------------------------------------------------------------------------------
public void putString(String s)
{
for (int i=0;i<s.get_Length();i++)
{
putChar(s.charAt(i));
}
}
//---------------------------------------------------------------------------------------------------
// 出力ファイルに1文字ずつ書く
//---------------------------------------------------------------------------------------------------
public void putChar(char c)
{
//まだOPENしてなかったら
if (!IsOpen)
{
//OPENする
textWriter = new System.IO.StreamWriter(fileName, false, System.Text.Encoding.GetEncoding("Shift_JIS"));
IsOpen = true;
}

//改行コードが渡されたら
if (c == NEWLINE)
{
//書き込み用バッファの内容を書き込み、バッファをクリアする
putLine();
}
else
{
//書き込み用バッファに1文字追加する
writeBuffer += c;
}
}
//---------------------------------------------------------------------------------------------------
// 書き込み用バッファの内容を書き込み、バッファをクリアする
//---------------------------------------------------------------------------------------------------
private void putLine()
{
textWriter.WriteLine(writeBuffer);
writeBuffer = "";
}
}