99import java .io .PrintStream ;
1010import java .io .PrintWriter ;
1111import java .io .StringWriter ;
12+ import java .nio .charset .Charset ;
1213import java .nio .file .Files ;
1314import java .util .Map ;
1415
@@ -44,16 +45,17 @@ void initCli() {
4445 options = new Options ();
4546 options .addOption ("v" , "version" , false , "Display version info" );
4647 options .addOption ("h" , "help" , false , "Display help and version info" );
47- // TODO options.addOption("j", "jsonargs", true, "Specify arguments as JSON object");
4848 options .addOption (Option .builder ("e" ).longOpt ("expression" )
4949 .argName ("file" )
5050 .hasArg ()
5151 .desc ("JSONata expression file to evaluate" )
5252 //.required()
5353 .build ());
5454 options .addOption ("i" , "input" , true , "JSON input file (- for stdin)" );
55+ options .addOption ("ic" , "icharset" , true , "Input character set (default=UTF-8)" );
5556 options .addOption ("f" , "format" , true , "Input format (default=auto)" );
5657 options .addOption ("o" , "output" , true , "JSON output file (default=stdout)" );
58+ options .addOption ("oc" , "ocharset" , true , "Output character set (default=UTF-8)" );
5759 options .addOption ("time" , false , "Print performance timers to stderr" );
5860 options .addOption ("c" , "compact" , false , "Compact JSON output (don't prettify)" );
5961 options .addOption (Option .builder ("b" ).longOpt ("bindings" ).
@@ -108,6 +110,9 @@ void run(String[] args) throws Throwable {
108110 bindingsStr = cmd .getOptionValue ("b" );
109111 Map <String , Object > bindingsObj = bindingsStr != null ? (Map <String , Object >)Json .parseJson (bindingsStr ) : null ;
110112
113+ String icharset = cmd .getOptionValue ("ic" , "UTF-8" );
114+ String ocharset = cmd .getOptionValue ("oc" , "UTF-8" );
115+
111116 InputStream in = null ;
112117 Object input = null ;
113118 {
@@ -132,15 +137,15 @@ void run(String[] args) throws Throwable {
132137 out = new FileOutputStream (arg );
133138 }
134139
135- PrintStream pout = new PrintStream (out );
140+ PrintStream pout = new PrintStream (out , false , ocharset );
136141
137142 long t0 = System .currentTimeMillis ();
138143
139144 String formatStr = cmd .getOptionValue ("f" , TerminalUtil .InputFormat .auto .name ());
140145 TerminalUtil .InputFormat format = TerminalUtil .InputFormat .valueOf (formatStr );
141146
142147 if (in !=null )
143- input = TerminalUtil .readInput (in , format );
148+ input = TerminalUtil .readInput (in , format , Charset . forName ( icharset ) );
144149
145150 long t1 = System .currentTimeMillis ();
146151
0 commit comments