Initializes and returns a session. @return session instance @throws IOException I/O exception
()
| 119 | * @throws IOException I/O exception |
| 120 | */ |
| 121 | private Session init() throws IOException { |
| 122 | if(local()) return new LocalSession(context, out); |
| 123 | |
| 124 | // user/password input |
| 125 | String username = context.soptions.get(StaticOptions.USER); |
| 126 | String password = context.soptions.get(StaticOptions.PASSWORD); |
| 127 | while(username.isEmpty()) { |
| 128 | Util.print(USERNAME + COLS); |
| 129 | username = Util.input(); |
| 130 | } |
| 131 | while(password.isEmpty()) { |
| 132 | Util.print(PASSWORD + COLS); |
| 133 | password = Util.password(); |
| 134 | } |
| 135 | |
| 136 | final String host = context.soptions.get(StaticOptions.HOST); |
| 137 | final int port = context.soptions.get(StaticOptions.PORT); |
| 138 | try { |
| 139 | return new ClientSession(host, port, username, password, out); |
| 140 | } catch(final ConnectException ex) { |
| 141 | Util.debug(ex); |
| 142 | throw new BaseXException(CONNECTION_ERROR_X, port); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns the base URI and the query string for the specified command input. |