public static void processString()

in src/java/org/apache/fulcrum/jce/crypto/cli/CLI2.java [311:351]


	public static void processString(String[] args) throws Exception {
		final String cipherMode;
		final char[] password;
		final String value;
		File targetFile = null;
		if (args.length > 3) {
			cipherMode = args[1];
			password = args[2].toCharArray();
			value = args[3];
		} else {
			value = null;
			cipherMode = null;
			password = null;
		}
		if (args.length == 5) {
			targetFile = new File(args[4]);
			File parentFile = targetFile.getParentFile();

			if (parentFile != null && (!parentFile.exists() || !parentFile.isDirectory())) {
				boolean success = parentFile.mkdirs();
				if (!success) {
					System.err.println("Error, could not create directory to write parent file");
				}
			}
		}

		if (value != null && !value.equals("")) {

			String result = processString(cipherMode, password, value);

			if (targetFile != null) {

				try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(targetFile),
						Charset.forName("UTF-8").newEncoder())) {
					osw.write(result);
				}
			} else {
				System.out.println(result);
			}
		}
	}