KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > framework > UserInput


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.cli.framework;
25
26 import java.io.InputStreamReader JavaDoc;
27 import java.io.BufferedReader JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30
31
32 /**
33     This class represents the user is in interactive mode.
34     This class provides the users response.
35  */

36 public class UserInput implements IUserInput
37 {
38
39     private InputStream JavaDoc mInputStr;
40     private boolean mInteractive;
41     private BufferedReader JavaDoc buffRead;
42
43
44     /**
45        Constructor which sets the InputStream and the interactive mode.
46        @param in is an InputStream object representation of users
47                    response.
48     */

49     public UserInput(InputStream JavaDoc in)
50     {
51     mInputStr = in;
52     mInteractive = true;
53     buffRead = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(mInputStr));
54     }
55
56
57     /**
58        Returns a boolean which tells the program is in interactive mode.
59     */

60     public boolean isInteractive()
61     {
62     return mInteractive;
63     }
64
65
66     /**
67        Closes the underlying input stream.
68     */

69     public void close() throws IOException JavaDoc
70     {
71     mInputStr.close();
72     }
73
74     /**
75      * Set the character encoding
76      * @param sEncoding - character encoding to set
77      */

78     public void setEncoding(String JavaDoc sEncoding) throws IOException JavaDoc
79     {
80 // buffRead.close();
81
InputStreamReader JavaDoc inStrReader = new InputStreamReader JavaDoc(
82                                 mInputStr, sEncoding);
83     buffRead = new BufferedReader JavaDoc(inStrReader);
84 // inStrReader.close();
85
}
86
87
88     /**
89        Returns a String representation of users response.
90        Could be next line in the stream provided.
91     */

92     public String JavaDoc getLine() throws IOException JavaDoc
93     {
94     //InputStreamReader inStrReader = new InputStreamReader(mInputStr);
95
//BufferedReader buffRead = new BufferedReader(inStrReader);
96
return buffRead.readLine();
97     }
98
99     /**
100      * Returns a Character representation of users response.
101      */

102     public int getChar() throws IOException JavaDoc
103     {
104     return buffRead.read();
105     }
106
107 }
108
109
Popular Tags