📄 indentwriter.java
字号:
/**
* IgaLib -> String
* Copyright (C) 2001 Tosiki IGA , IgaLib project member
* (http://homepage2.nifty.com/igat/igapyon/index.html)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package jp.ne.nifty.iga.tosiki.string;
import java.io.*;
/**
* 僀儞僨儞僩晅偒彂弌Writer僋儔僗<BR>
* 僜乕僗僐乕僪傪婡夿揑偵弌椡偡傞嵺偵昁梫偵側傞 僀儞僨儞僩晅偒Writer僋儔僗偱偡丅
* 僐儊儞僩傪彂偒弌偡婡擻傕旛偊傑偡丅<BR>
*
* @author Tosiki IGA
*/
public class IndentWriter
extends PrintWriter
{
protected static final boolean IS_DEBUG=false;
protected int iIndent=0;
protected boolean isComment=false;
protected boolean isPastLineComment=false;
/**
* 僀儞僨儞僩晅偒彂弌Writer僋儔僗偺僐儞僗僩儔僋僞
*
* @param Writer writer 楢寢偡傞尦偺Writer
*/
public IndentWriter(Writer writer)
{
super(writer);
}
/**
* 暥帤楍傪Writer傊彂偒崬傒傑偡丅<BR>
* 偙偺儊僜僢僪偼 Writer偲偄偆娤揰偐傜偼 偐側傝亀晛捠亁偱偼偁傝傑偣傫丅
* 傑偨 偙偺儊僜僢僪偺傒偑僀儞僨儞僩懳徾偱偡丅
*
* @param String strbuf 彂偒崬傒暥帤楍
*/
public void println(String strBuf)
{
fillIndent(iIndent);
if(isComment)
{
if(isPastLineComment==false)
{
isPastLineComment=true;
super.println("/**");
fillIndent(iIndent);
}
super.print(" * ");
}
if(isComment==false)
{
if(isPastLineComment==true)
{
isPastLineComment=false;
super.println(" */");
fillIndent(iIndent);
}
}
super.println(strBuf);
}
/**
* 暥帤楍傪Writer傊堦帪揑僀儞僨儞僩偲嫟偵彂偒崬傒傑偡丅<BR>
* 偙偺儊僜僢僪偼 Writer偲偄偆娤揰偐傜偼 偐側傝亀晛捠亁偱偼偁傝傑偣傫丅
* 傑偨 偙偺儊僜僢僪偺傒偑僀儞僨儞僩懳徾偱偡丅
*
* @param String strbuf 彂偒崬傒暥帤楍
*/
public void println(int iTempIndent,String strBuf)
{
addIndent(iTempIndent);
println(strBuf);
addIndent(-iTempIndent);
}
protected void fillIndent(int arg)
{
for(int index=arg;index>0;index--)
{
super.print('\t');
}
}
/**
* 僀儞僨儞僩傪憹尭偝偣傑偡<BR>
* 偙偺儊僜僢僪偼 PrintWriter偲偄偆娤揰偐傜偼 偐側傝亀晛捠亁偱偼偁傝傑偣傫丅
*
* @param int arg 僀儞僨儞僩偺憹尭嵎暘
*/
public final void addIndent(int arg)
{
iIndent+=arg;
}
public final void beginComment()
{
isComment=true;
}
public final void endComment()
{
isComment=false;
}
public static final void convert(File fileInput,File fileOutput)
throws IOException
{
BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(fileInput)));
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileOutput)));
for(;;)
{
String strRead=reader.readLine();
if(strRead==null)break;
writer.write("\t\tout.println(\"");
writer.write(EscapeUtil.encodeQuote(strRead));
writer.write("\");");
writer.newLine();
}
reader.close();
writer.flush();
writer.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -