Java tutorial
/******************************************************************************* * Copyright 2016 Adobe Systems Incorporated. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package com.adobe.aem.demomachine; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.log4j.Logger; import org.apache.commons.codec.binary.Base64; public class Base64Encoder { static Logger logger = Logger.getLogger(Base64.class); public static void main(String[] args) throws IOException { String value = null; // Command line options for this tool Options options = new Options(); options.addOption("v", true, "Value"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { value = cmd.getOptionValue("v"); } if (value == null) { System.out.println("Command line parameters: -v value"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } byte[] encodedBytes = Base64.encodeBase64(value.getBytes()); System.out.println(new String(encodedBytes)); } }