Wednesday, 4 September 2013

get "alphabet" plain text characters from telnet ASCI

get "alphabet" plain text characters from telnet ASCI

Referencing tintin, I'm reading data from an InputStream, character by
character to capture all output, even before an end-of-line (CRLF). For
the most part, it works fine. However, ANSI (?) colors interfere with some
of the regex.
Keeping in mind that it must be character by character, how can I convert
the stream data to an encoding which is just plain text? Certainly I want
to receive ANSI or VT100 text, but want to change the character encoding
as necessary.
Reading characters:
package telnet;
import static java.lang.System.out;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;
public class InputStreamWorker {
private final static Logger LOG =
Logger.getLogger(InputStreamWorker.class.getName());
public InputStreamWorker() {
}
public void print(final InputStream inputStream, final
ConcurrentLinkedQueue<Character> charQueue) {
Thread print = new Thread() {
StringBuilder sb = new StringBuilder();
@Override
public void run() {
try {
char ch = (char) inputStream.read();
sb.append(ch);
while (255 > ch && ch >= 0) {
charQueue.add(ch);
ch = (char) inputStream.read();
System.out.print(ch);
}
} catch (IOException ex) {
out.println("cannot read inputStream:\t" + ex);
}
}
};
print.start();
}
}
Looking at how colors work, is it possible, can the characters be
converted along the lines of toLowercase to get just the character value,
from the alphabet, without anything additional?

No comments:

Post a Comment