Error on running Java example from unsuitable Console.

GitOrigin-RevId: d555b8d4763e77e1d5313b929bb7b257a237dcc6
This commit is contained in:
levlam 2018-03-14 14:50:42 +03:00
parent 1b75824e3e
commit b48b0c5ece
2 changed files with 8 additions and 5 deletions

View File

@ -27,7 +27,7 @@ Compiled TDLib shared library and Java example after that will be placed in bin/
Now you can run Java example:
```
cd <path to TDLib sources>/example/java/bin
java -Djava.library.path=. org/drinkless/tdlib/example/Example
java '-Djava.library.path=.' org/drinkless/tdlib/example/Example
```
If you get "Could NOT find JNI ..." error from CMake, you need to specify to CMake path to the installed JDK, for example, "-DJAVA_HOME=/usr/lib/jvm/java-8-oracle/".

View File

@ -49,6 +49,7 @@ public final class Example {
private static final ConcurrentMap<Integer, TdApi.BasicGroupFullInfo> basicGroupsFullInfo = new ConcurrentHashMap<Integer, TdApi.BasicGroupFullInfo>();
private static final ConcurrentMap<Integer, TdApi.SupergroupFullInfo> supergroupsFullInfo = new ConcurrentHashMap<Integer, TdApi.SupergroupFullInfo>();
private static final Console console = System.console();
private static final String newLine = System.getProperty("line.separator");
static {
@ -100,19 +101,16 @@ public final class Example {
client.send(new TdApi.CheckDatabaseEncryptionKey(), new AuthorizationRequestHandler());
break;
case TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR: {
Console console = System.console();
String phoneNumber = console.readLine("Please enter phone number: ");
client.send(new TdApi.SetAuthenticationPhoneNumber(phoneNumber, false, false), new AuthorizationRequestHandler());
break;
}
case TdApi.AuthorizationStateWaitCode.CONSTRUCTOR: {
Console console = System.console();
String code = console.readLine("Please enter authentication code: ");
client.send(new TdApi.CheckAuthenticationCode(code, "", ""), new AuthorizationRequestHandler());
break;
}
case TdApi.AuthorizationStateWaitPassword.CONSTRUCTOR: {
Console console = System.console();
String password = console.readLine("Please enter password: ");
client.send(new TdApi.CheckAuthenticationPassword(password), new AuthorizationRequestHandler());
break;
@ -164,7 +162,7 @@ public final class Example {
}
private static void getCommand() {
String command = System.console().readLine("Enter command (gcs - GetChats, gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ");
String command = console.readLine("Enter command (gcs - GetChats, gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ");
String[] commands = command.split(" ", 2);
try {
switch (commands[0]) {
@ -264,6 +262,11 @@ public final class Example {
}
public static void main(String[] args) throws InterruptedException {
if (console == null) {
System.err.println("This example requires Console for user interaction. On Windows cmd or PowerShell should be used");
System.exit(1);
}
// disable TDLib log
Log.setVerbosityLevel(0);
if (!Log.setFilePath("tdlib.log")) {