public KernelConfigurationFile(final String[] args) { if (args.length > 2) { logger.error("Invalid parameters passed to the Kernel. Expected one or two parameter, found " + args.length); for (String string : args) { logger.error(string); } System.exit(1); } this.config = getConfig(args[0]); if (args.length == 2) { String contextAsJson = null; try { contextAsJson = new String(Base64.decode(args[1]), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } this.context = Optional.of(contextAsJson); } }
/** * Decodes a BASE64 encoded byte array. All illegal characters will be * ignored and can handle both arrays with and without line separators. * * @param sArr * The source array. Length 0 will return an empty array. * <code>null</code> will throw an exception. * @return The decoded array of bytes. May be of length 0. Will be * <code>null</code> if the legal characters (including '=') isn't * divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(byte[] sArr) { return decode(sArr, 0, sArr.length); }
/** * <p> * Assumes that commandPart is <b>not</b> empty. * </p> * * @param commandPart * @return The byte array corresponding to this command part. */ public final static byte[] getBytes(String commandPart) { return Base64.decode(commandPart.substring(1)); }