@Override protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException { if (file != null) { final Path targetFile = file.toPath(); try { getManager(invoc.getPmSession()).exportProvisioningConfig(targetFile); } catch (ProvisioningException | IOException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } invoc.println("Provisioning file generated in " + targetFile); } else { ByteArrayOutputStream output = null; try { ProvisioningConfig config = getManager(invoc.getPmSession()).getProvisioningConfig(); output = new ByteArrayOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)); ProvisioningXmlWriter.getInstance().write(config, writer); } catch (Exception e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } try { invoc.println(output.toString(StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e); } } }