Apache telnet uses InputStream, which I want to read as a String (or String like data).
How can I transform the InputStream into something easier (for me) to deal with, a StringBuffer or similar.
Apache telnet uses InputStream, which I want to read as a String (or String like data).
How can I transform the InputStream into something easier (for me) to deal with, a StringBuffer or similar.
 
    
    You can consider IOUtils.toString(is) from Apache Common IO
public static String toString(InputStream input)
                       throws IOException
from the doc:
This method buffers the input internally, so there is no need to use a BufferedInputStream.
 
    
    You cant transform the InputStream into StringBuffer. But if you want to make use of StringBuffer then you can read the input from InputStream as a int and append it to StringBuffer like below.
int i=fis.read(); //it will read Character from stream and returns ascii value of char.
StringBuffer sb=new StringBuffer();
sb.append((char)i); //This will cast int into character and append to StringBuffer.
 
    
    This is partway there:
package teln;
import static java.lang.System.out;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketException;
import org.apache.commons.net.telnet.TelnetClient;
public final class ConnectMUD {
    private static String EOL = "/[#]/";
    private static TelnetClient tc;
    public static void main(String[] args) throws SocketException, IOException {
        tc = new TelnetClient();
        tc.connect("some_mud.com", 123);
        readLines(tc.getInputStream());
    }
    private static void readLines(InputStream in) throws IOException {
        InputStreamReader is = new InputStreamReader(in);
        StringBuilder sb = new StringBuilder();
        BufferedReader br = new BufferedReader(is);
        String read = br.readLine();
        while (read != null) {
            out.println(read);
            sb.append(read);
            read = br.readLine();
            parseLine(read);
        }
    }
    private static void parseLine(String read) {
        login(read);
    }
    private static void login(String read) {
        //hmm, how do you know when you
        //get some funky, non-standard login?
        //look for an EOL of some sort?
    }
}
there's a potential for some very large strings there, but I'm just focused on functionality first. Just trying to start parsing lines for playing da MUD.
