8d5281198c5fe2b95c3bbd790cfd62573dc1074a
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / util / SubStandardConsole.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.cadi.util;
23
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27
28 // Substandard, because System.in doesn't do Passwords..
29 public class SubStandardConsole implements MyConsole {
30         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
31         @Override
32         public String readLine(String fmt, Object... args) {
33                 String rv;
34                 try {
35                         System.out.printf(fmt,args);
36                         rv = br.readLine();
37                         if(args.length==1 && rv.length()==0) {
38                                 rv = args[0].toString();
39                         }
40                 } catch (IOException e) {
41                         System.err.println("uh oh...");
42                         rv = "";
43                 }
44                 return rv;
45         }
46
47         @Override
48         public char[] readPassword(String fmt, Object... args) {
49                 try {
50                         System.out.printf(fmt,args);
51                         return br.readLine().toCharArray();
52                 } catch (IOException e) {
53                         System.err.println("uh oh...");
54                         return new char[0];
55                 }
56         }
57
58         @Override
59         public void printf(String fmt, Object... args) {
60                 System.out.printf(fmt, args);
61         }
62 }