All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.opensecreto.jconsole.StreamConsoleAdapter Maven / Gradle / Ivy

The newest version!
package ru.opensecreto.jconsole;

import java.io.*;

public class StreamConsoleAdapter implements ConsoleAdapter {

    private final PrintWriter out;
    private final BufferedReader in;

    public StreamConsoleAdapter(PrintStream out, InputStream in) {
        this.out = new PrintWriter(out);
        this.in = new BufferedReader(new InputStreamReader(in));
    }

    @Override
    public PrintWriter writer() {
        return out;
    }

    @Override
    public Reader reader() {
        return in;
    }

    @Override
    public ConsoleAdapter format(String fmt, Object... args) {
        out.format(fmt, args).flush();
        return this;
    }

    @Override
    public ConsoleAdapter printf(String format, Object... args) {
        out.printf(format, args).flush();
        return this;
    }

    @Override
    public String readLine(String fmt, Object... args) throws IOException {
        out.printf(fmt, args).flush();
        return in.readLine();
    }

    @Override
    public String readLine() throws IOException {
        return in.readLine();
    }

    @Override
    public char[] readPassword(String fmt, Object... args) throws IOException {
        out.printf(fmt, args).flush();
        return in.readLine().toCharArray();
    }

    @Override
    public char[] readPassword() throws IOException {
        return in.readLine().toCharArray();
    }

    @Override
    public void flush() {
        out.flush();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy