View Javadoc
1   package org.cyclopsgroup.jmxterm.io;
2   
3   import org.apache.commons.lang3.Validate;
4   
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.io.InputStreamReader;
8   import java.io.LineNumberReader;
9   
10  /**
11   * Implementation of {@link CommandInput} with an input stream
12   * 
13   * @author <a href="mailto:jiaqi.guo@gmail.com">Jiaqi Guo</a>
14   */
15  public class InputStreamCommandInput extends CommandInput {
16    private final LineNumberReader reader;
17  
18    /**
19     * @param in Given input stream
20     */
21    public InputStreamCommandInput(InputStream in) {
22      Validate.notNull(in, "Input stream can't be NULL");
23      reader = new LineNumberReader(new InputStreamReader(in));
24    }
25  
26    @Override
27    public String readLine() throws IOException {
28      return reader.readLine();
29    }
30  
31    @Override
32    public String readMaskedString(String prompt) throws IOException {
33      throw new UnsupportedOperationException("Reading password from stream is not supported");
34    }
35  
36    @Override
37    public void close() throws IOException {
38      reader.close();
39    }
40  }