use of org.jline.terminal.impl.DumbTerminal in project Payara by payara.
the class AsadminTrustManager method isItOKToAddCertToTrustStore.
/**
* Displays the certificate and prompts the user whether or
* not it is trusted.
* @param c
* @throws IOException
* @return true if the user trusts the certificate
*/
private boolean isItOKToAddCertToTrustStore(X509Certificate c) {
if (!interactive) {
return true;
}
String result = null;
LineReader lineReader = null;
try {
lineReader = LineReaderBuilder.builder().terminal(new DumbTerminal(System.in, System.out)).build();
result = lineReader.readLine(STRING_MANAGER.get("certificateTrustPrompt"));
} catch (IOException ioe) {
logger.log(Level.WARNING, "Error instantiating console", ioe);
} finally {
if (lineReader != null && lineReader.getTerminal() != null) {
try {
lineReader.getTerminal().close();
} catch (IOException ioe) {
logger.log(Level.WARNING, "Error closing terminal", ioe);
}
}
}
return result != null && result.equalsIgnoreCase("y");
}
use of org.jline.terminal.impl.DumbTerminal in project flink by apache.
the class CliClientITCase method runSqlStatements.
/**
* Returns printed results for each ran SQL statements.
*
* @param statements the SQL statements to run
* @return the printed results on SQL Client
*/
private List<Result> runSqlStatements(List<String> statements) throws IOException {
final String sqlContent = String.join("", statements);
DefaultContext defaultContext = new DefaultContext(Collections.emptyList(), new Configuration(MINI_CLUSTER_RESOURCE.getClientConfiguration()).set(ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR, ExecutionConfigOptions.LegacyCastBehaviour.DISABLED), Collections.singletonList(new DefaultCLI()));
final Executor executor = new LocalExecutor(defaultContext);
InputStream inputStream = new ByteArrayInputStream(sqlContent.getBytes());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
String sessionId = executor.openSession("test-session");
try (Terminal terminal = new DumbTerminal(inputStream, outputStream);
CliClient client = new CliClient(() -> terminal, sessionId, executor, historyPath, HideSqlStatement.INSTANCE)) {
client.executeInInteractiveMode();
String output = new String(outputStream.toByteArray());
return normalizeOutput(output);
}
}
use of org.jline.terminal.impl.DumbTerminal in project flink by apache.
the class CliClientTest method testHistoryFile.
@Test
public void testHistoryFile() throws Exception {
final MockExecutor mockExecutor = new MockExecutor();
String sessionId = mockExecutor.openSession("test-session");
InputStream inputStream = new ByteArrayInputStream("help;\nuse catalog cat;\n".getBytes());
Path historyFilePath = historyTempFile();
try (Terminal terminal = new DumbTerminal(inputStream, new TerminalUtils.MockOutputStream());
CliClient client = new CliClient(() -> terminal, sessionId, mockExecutor, historyFilePath, null)) {
client.executeInInteractiveMode();
List<String> content = Files.readAllLines(historyFilePath);
assertThat(content.size()).isEqualTo(2);
assertThat(content.get(0)).contains("help");
assertThat(content.get(1)).contains("use catalog cat");
}
}
Aggregations