File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
src/net/sharksystem/asap/util
test/net/sharksystem/asap Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ package net .sharksystem .asap .util ;
2+
3+ import net .sharksystem .asap .ASAPException ;
4+ import net .sharksystem .cmdline .CmdLineUI ;
5+
6+ import java .io .ByteArrayInputStream ;
7+ import java .io .ByteArrayOutputStream ;
8+ import java .io .IOException ;
9+ import java .io .PrintStream ;
10+ import java .util .ArrayList ;
11+ import java .util .List ;
12+
13+ public class Batchprocessor {
14+ private final boolean cleanup ;
15+ List <String > cmdList = new ArrayList <>();
16+
17+ public Batchprocessor () {
18+ this (true );
19+ }
20+
21+ public Batchprocessor (boolean cleanup ) {
22+ this .cleanup = cleanup ;
23+ }
24+
25+ public void addCommand (String cmd ) {
26+ this .cmdList .add (cmd );
27+ }
28+
29+ public void execute () throws IOException , ASAPException {
30+ // prepare output
31+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
32+ PrintStream ps = new PrintStream (baos );
33+
34+ for (String cmd : this .cmdList ) {
35+ ps .println (cmd );
36+ }
37+
38+ ByteArrayInputStream bais = new ByteArrayInputStream (baos .toByteArray ());
39+
40+ CmdLineUI cmdLineUI = new CmdLineUI (System .out , bais );
41+ if (this .cleanup ) {
42+ System .out .println ("clean asap peers folders" );
43+ cmdLineUI .doResetASAPStorages ();
44+ }
45+
46+ cmdLineUI .runCommandLoop ();
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ package net .sharksystem .asap ;
2+
3+ import net .sharksystem .asap .util .Batchprocessor ;
4+ import org .junit .Test ;
5+
6+ import java .io .IOException ;
7+
8+ public class BatchprocessorTest {
9+ @ Test
10+ public void basicTest () throws IOException , ASAPException {
11+ Batchprocessor batchprocessor = new Batchprocessor ();
12+ batchprocessor .addCommand ("newpeer Clara" );
13+
14+ batchprocessor .addCommand (
15+ "newapp Clara chat\n " +
16+ "newmessage Clara chat sn2://abChat HiBob" );
17+
18+ batchprocessor .execute ();
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments