* @param args The command-line arguments provided to this program.
*/
public static void main(String[] args)
{
Message description = INFO_BASE64_TOOL_DESCRIPTION.get();
SubCommandArgumentParser argParser =
new SubCommandArgumentParser(Base64.class.getName(), description,
false);
BooleanArgument showUsage = null;
StringArgument encodedData = null;
StringArgument encodedFile = null;
StringArgument rawData = null;
StringArgument rawFile = null;
StringArgument toEncodedFile = null;
StringArgument toRawFile = null;
SubCommand decodeSubCommand = null;
SubCommand encodeSubCommand = null;
try
{
decodeSubCommand = new SubCommand(argParser, "decode",
INFO_BASE64_DECODE_DESCRIPTION.get());
encodeSubCommand = new SubCommand(argParser, "encode",
INFO_BASE64_ENCODE_DESCRIPTION.get());
encodedData = new StringArgument("encodeddata", 'd', "encodedData", false,
false, true, INFO_DATA_PLACEHOLDER.get(), null,
null,
INFO_BASE64_ENCODED_DATA_DESCRIPTION.get());
decodeSubCommand.addArgument(encodedData);
encodedFile = new StringArgument("encodedfile", 'f', "encodedDataFile",
false, false, true, INFO_PATH_PLACEHOLDER.get(),
null, null,
INFO_BASE64_ENCODED_FILE_DESCRIPTION.get());
decodeSubCommand.addArgument(encodedFile);
toRawFile = new StringArgument("torawfile", 'o', "toRawFile", false,
false, true, INFO_PATH_PLACEHOLDER.get(),
null, null,
INFO_BASE64_TO_RAW_FILE_DESCRIPTION.get());
decodeSubCommand.addArgument(toRawFile);
rawData = new StringArgument("rawdata", 'd', "rawData", false, false,
true, INFO_DATA_PLACEHOLDER.get(), null,
null,
INFO_BASE64_RAW_DATA_DESCRIPTION.get());
encodeSubCommand.addArgument(rawData);
rawFile = new StringArgument("rawfile", 'f', "rawDataFile", false, false,
true, INFO_PATH_PLACEHOLDER.get(), null,
null,
INFO_BASE64_RAW_FILE_DESCRIPTION.get());
encodeSubCommand.addArgument(rawFile);
toEncodedFile = new StringArgument("toencodedfile", 'o', "toEncodedFile",
false, false, true, INFO_PATH_PLACEHOLDER.get(),
null, null,
INFO_BASE64_TO_ENCODED_FILE_DESCRIPTION.get());
encodeSubCommand.addArgument(toEncodedFile);
ArrayList<SubCommand> subCommandList = new ArrayList<SubCommand>(2);
subCommandList.add(decodeSubCommand);
subCommandList.add(encodeSubCommand);
showUsage = new BooleanArgument("help", 'H', "help",
INFO_BASE64_HELP_DESCRIPTION.get());
argParser.addGlobalArgument(showUsage);
argParser.setUsageGroupArgument(showUsage, subCommandList);
argParser.setUsageArgument(showUsage, NullOutputStream.printStream());
}
catch (ArgumentException ae)
{
System.err.println(ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage()));
System.exit(1);
}
try
{
argParser.parseArguments(args);
}
catch (ArgumentException ae)
{
System.err.println(
ERR_ERROR_PARSING_ARGS.get(ae.getMessage()).toString());
System.exit(1);
}
SubCommand subCommand = argParser.getSubCommand();
if (argParser.isUsageArgumentPresent())
{
if (subCommand == null)
{
System.out.println(argParser.getUsage());
}
else
{
MessageBuilder messageBuilder = new MessageBuilder();
argParser.getSubCommandUsage(messageBuilder, subCommand);
System.out.println(messageBuilder.toString());
}
return;
}
if (argParser.isVersionArgumentPresent())
{
// We have to print the version since we have set a NullOutputStream on
// the parser
try
{
DirectoryServer.printVersion(System.out);
System.exit(0);
}
catch (Throwable t)
{
// Bug
System.err.println(ERR_UNEXPECTED.get(t.toString()).toString());
System.exit(1);
}
}
if (subCommand == null)
{
System.err.println(argParser.getUsage());
System.exit(1);
}
if (subCommand.getName().equals(encodeSubCommand.getName()))
{
byte[] dataToEncode = null;