/*
* Process the --locale, --encoding and --colors options.
*/
Option option = null; // In case of IllegalArgumentException.
String value = null;
final Console console;
final boolean explicitEncoding;
try {
value = options.get(option = Option.LOCALE);
locale = (value != null) ? Locales.parse(value) : Locale.getDefault();
value = options.get(option = Option.TIMEZONE);
timezone = (value != null) ? TimeZone.getTimeZone(value) : TimeZone.getDefault();
value = options.get(option = Option.ENCODING);
explicitEncoding = (value != null);
encoding = explicitEncoding ? Charset.forName(value) : Charset.defaultCharset();
value = options.get(option = Option.COLORS);
console = System.console();
colors = (value != null) ? Option.COLORS.parseBoolean(value) : (console != null) && X364.isAnsiSupported();
} catch (IllegalArgumentException e) {
final String name = option.name().toLowerCase(Locale.US);
throw new InvalidOptionException(Errors.format(Errors.Keys.IllegalOptionValue_2, name, value), name);
}
/*
* Creates the writers. If this sub-command is created for JUnit test purpose, then we will send the
* output to a StringBuffer. Otherwise the output will be sent to the java.io.Console if possible,
* or to the standard output stream otherwise.
*/
if (isTest) {
final StringWriter s = new StringWriter();
outputBuffer = s.getBuffer();
out = new PrintWriter(s);
err = out;
} else {
outputBuffer = null;
err = (console != null) ? console.writer() : new PrintWriter(System.err, true);
if (!explicitEncoding && console != null) {
out = console.writer();
} else {
if (explicitEncoding) {
out = new PrintWriter(new OutputStreamWriter(System.out, encoding), true);
} else {
out = new PrintWriter(System.out, true);