📄 jacsoncmd.java
字号:
/*
* JacsonCmd 0.00
*
*/
package com.jhkdesign.console.cmd;
import java.io.PrintStream;
import java.io.IOException;
import com.jhkdesign.console.ArgumentInt;
import com.jhkdesign.console.ResultInt;
import com.jhkdesign.console.CommandException;
import de.spieleck.config.ConfigNode;
import de.spieleck.app.jacson.Jacson;
import de.spieleck.app.jacson.JacsonNames;
import de.spieleck.app.jacson.JacsonReport;
import de.spieleck.app.jacson.JacsonState;
import de.spieleck.app.jacson.JacsonChunkSource;
import de.spieleck.app.jacson.source.LineChunkSource;
/**
* JacsonCmd
*
* JacsonCmd wraps a Jacson into a
* The reasons for doing so are listed in
* com.jhkdesign.console.cmd.CatCmd.java.
*
* @version 0.0.0 2003/5/15
* @author Frank Nestel ( nestefan -at.nospam- users.sf.net )
*/
public class JacsonCmd
extends CommandAbst
implements JacsonNames
{
public static final String VERSION =
("jacson 0.0.0\n" +
"Written by Frank Nestel.\n" +
"\n" + SHORT_COPYRIGHT);
public static final String USAGE =
("Usage: jacson CONFIG_FILE FILE1 [FILE2] [FILE3] ...\n" +
"Feed files through a Jacson process defined by the configuration.\n"+
"\n" +
"Example:\n" +
" tar wc.conf long.text.file" +
" # Do some counting on the file long.text.file.\n" +
"\n" +
"\n" + BUG_REPORT_INFO);
public JacsonCmd() {}
public String getVersion() {
return VERSION;
}
public String getUsage() {
return USAGE;
}
public ResultInt execute(ArgumentInt arg)
throws CommandException, IllegalArgumentException {
ResultInt rst = arg.getResult();
PrintStream out = new PrintStream(arg.getOutputStream());
PrintStream err = new PrintStream(arg.getErrorStream());
if (CmdUtil.handleUsageOrVersion(this, arg, out)) {
return rst;
}
else if ( arg.countArguments() < 1 )
{
out.println(USAGE);
}
String[] args = arg.getArguments();
JacsonState rootState = new JJacketJacsonState(arg);
int argsStart = Jacson.paramArgs(args, rootState);
try
{
ConfigNode config = Jacson.obtainConfig(args[0], rootState);
Jacson stat = new Jacson(config, rootState);
JacsonReport jr = stat.getReport();
//
jr.begin(JS_REP_PROC);
long t1 = System.currentTimeMillis();
// We either run on the commandline filenames or on stdin
if ( argsStart < args.length )
{
for(int i = argsStart; i < args.length; i++)
{
try
{
JacsonChunkSource ch =new LineChunkSource(args[i],true);
stat.run(ch);
}
catch ( IOException e )
{
e.printStackTrace(err);
}
}
}
else
{
JacsonChunkSource ch = new LineChunkSource(
arg.getInputStream(), false);
}
long dt = System.currentTimeMillis() - t1;
jr.report(JS_REP_TIME, ""+dt);
jr.end();
stat.summary();
jr.finish(false);
}
catch (Exception e)
{
throw new CommandException(e.toString());
}
return rst;
}
}
//
// Jacson - Text Filtering with Java.
// Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net)
//
// 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
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -