public static PasswordReader create() { final Console console = System.console(); if(console == null) { return new InputStreamPasswordReader(System.in); } else { return new ConsolePasswordReader(console); } }
static <T> T execute(XmlProcessingCallback<T> callback) { try { return callback.doExecute(); } catch (IOException | JAXBException | TransformerException ex) { throw new ConfigException(ex); } }
private static void output(CommandLine commandLine, Config config) throws IOException { if (commandLine.hasOption("output")) { final Path outputConfigFile = Paths.get(commandLine.getOptionValue("output")); try (OutputStream out = Files.newOutputStream(outputConfigFile, CREATE_NEW)) { JaxbUtil.marshal(config, out); } } else { JaxbUtil.marshal(config, System.out); } } }
public static void marshal(Object object, OutputStream outputStream) { try { MarshallerBuilder.create().build() .marshal(object, outputStream); } catch (Throwable ex) { Optional<ConstraintViolationException> validationException = unwrapConstraintViolationException(ex); if (validationException.isPresent()) { throw validationException.get(); } throw new ConfigException(ex); } }
public static String marshalToStringNoValidation(Object object) { return IOCallback.execute(() -> { try (OutputStream out = new ByteArrayOutputStream()) { marshalWithNoValidation(object, out); return out.toString(); } }); }
private Optional<ArgonOptions> argonOptions(final CommandLine commandLine) throws IOException { if (commandLine.hasOption("keygenconfig")) { final String pathName = commandLine.getOptionValue("keygenconfig"); final InputStream configStream = Files.newInputStream(Paths.get(pathName)); final ArgonOptions argonOptions = JaxbUtil.unmarshal(configStream, ArgonOptions.class); return Optional.of(argonOptions); } return Optional.empty(); }
private static Transformer createMaskingXslTransformer() { return XmlProcessingCallback.execute(() -> { try (InputStream inputStream = JaxbUtil.class.getResourceAsStream("/xsl/mask-config.xsl")) { return TransformerFactory.newInstance().newTransformer(new StreamSource(inputStream)); } }); }
/** * Requests user input for a password until two matching consecutive entries are made * * @return The password that the user has input */ default String requestUserPassword() { for(;;) { System.out.println("Enter a password if you want to lock the private key or leave blank"); final String password = this.readPasswordFromConsole(); System.out.println("Please re-enter the password (or lack of) to confirm"); final String passwordCheck = this.readPasswordFromConsole(); if(Objects.equals(password, passwordCheck)) { return password; } else { System.out.println("Passwords did not match, try again..."); } } }
@Override public void addPeer(String url) { this.config.addPeer(new Peer(url)); configFileStore.save(config); }
private static void output(CommandLine commandLine, Config config) throws IOException { if (commandLine.hasOption("output")) { final Path outputConfigFile = Paths.get(commandLine.getOptionValue("output")); try (OutputStream out = Files.newOutputStream(outputConfigFile, CREATE_NEW)) { JaxbUtil.marshal(config, out); } } else { JaxbUtil.marshal(config, System.out); } } }
@Override public void save(Config config) { IOCallback.execute(() -> { Path temp = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); try(OutputStream fout = Files.newOutputStream(temp)){ JaxbUtil.marshalWithNoValidation(config, fout); } Files.copy(temp, path,StandardCopyOption.REPLACE_EXISTING); return null; }); } }
public static PasswordReader create() { final Console console = System.console(); if(console == null) { return new InputStreamPasswordReader(System.in); } else { return new ConsolePasswordReader(console); } }
private void loadKeys() { this.inlineKeypair = new InlineKeypair( IOCallback.execute(() -> new String(Files.readAllBytes(this.publicKeyPath), UTF_8)), JaxbUtil.unmarshal( IOCallback.execute(() -> Files.newInputStream(privateKeyPath)), KeyDataConfig.class ) ); }
static <T> T execute(XmlProcessingCallback<T> callback) { try { return callback.doExecute(); } catch (IOException | JAXBException | TransformerException ex) { throw new ConfigException(ex); } }
private static Transformer createMaskingXslTransformer() { return XmlProcessingCallback.execute(() -> { try (InputStream inputStream = JaxbUtil.class.getResourceAsStream("/xsl/mask-config.xsl")) { return TransformerFactory.newInstance().newTransformer(new StreamSource(inputStream)); } }); }
/** * Requests user input for a password until two matching consecutive entries are made * * @return The password that the user has input */ default String requestUserPassword() { for(;;) { System.out.println("Enter a password if you want to lock the private key or leave blank"); final String password = this.readPasswordFromConsole(); System.out.println("Please re-enter the password (or lack of) to confirm"); final String passwordCheck = this.readPasswordFromConsole(); if(Objects.equals(password, passwordCheck)) { return password; } else { System.out.println("Passwords did not match, try again..."); } } }
public static String marshalToString(Object object) { return IOCallback.execute(() -> { try (OutputStream out = new ByteArrayOutputStream()) { marshal(object, out); return out.toString(); } }); }
@Override public void save(Config config) { IOCallback.execute(() -> { Path temp = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); try(OutputStream fout = Files.newOutputStream(temp)){ JaxbUtil.marshalWithNoValidation(config, fout); } Files.copy(temp, path,StandardCopyOption.REPLACE_EXISTING); return null; }); } }
public static String marshalToString(Object object) { return IOCallback.execute(() -> { try (OutputStream out = new ByteArrayOutputStream()) { marshal(object, out); return out.toString(); } }); }
public static String marshalToStringNoValidation(Object object) { return IOCallback.execute(() -> { try (OutputStream out = new ByteArrayOutputStream()) { marshalWithNoValidation(object, out); return out.toString(); } }); }