01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17:
18: package org.apache.harmony.tools.jarsigner;
19:
20: import java.io.IOException;
21: import java.io.InputStreamReader;
22:
23: /**
24: * Class to interact with user - ask for confirmations, and necessary parameters
25: * which haven't been set in the command line.
26: */
27: class UserInteractor {
28: // used to get additional data prompted
29: private static InputStreamReader in = new InputStreamReader(
30: System.in);
31:
32: // buffer for the data read
33: private static char[] readData = new char[256];
34:
35: // number of symbols read
36: private static int charsRead;
37:
38: // length of the "\r\n" which is added to the end of the line,
39: // when ENTER is pressed.
40: private static int newLineLength = 2;
41:
42: // Prints prompt and waits the user to enter the needed data,
43: // the data is returned.
44: static char[] getDataFromUser(String prompt) throws IOException {
45: System.out.println(prompt);
46: charsRead = in.read(readData);
47: char[] password = new char[charsRead - newLineLength];
48: System.arraycopy(readData, 0, password, 0, charsRead
49: - newLineLength);
50: return password;
51: }
52: }
|