- public void run () {
- int c;
-
- try {
- for (;;) {
- c = libaltos.altos_getchar(altos, 0);
- if (Thread.interrupted())
- break;
- if (c == libaltosConstants.LIBALTOS_ERROR) {
- for (int e = 0; e < monitors.size(); e++) {
- LinkedBlockingQueue<AltosLine> q = monitors.get(e);
- q.put(new AltosLine());
- }
- reply_queue.put (new AltosLine());
- break;
- }
- if (c == libaltosConstants.LIBALTOS_TIMEOUT)
- continue;
- if (c == '\r')
- continue;
- synchronized(this) {
- if (c == '\n') {
- if (line_count != 0) {
- try {
- line = new String(line_bytes, 0, line_count, "UTF-8");
- } catch (UnsupportedEncodingException ue) {
- line = "";
- for (int i = 0; i < line_count; i++)
- line = line + line_bytes[i];
- }
- if (line.startsWith("VERSION") || line.startsWith("CRC")) {
- for (int e = 0; e < monitors.size(); e++) {
- LinkedBlockingQueue<AltosLine> q = monitors.get(e);
- q.put(new AltosLine (line));
- }
- } else {
- if (debug)
- System.out.printf("\t\t\t\t\t%s\n", line);
- reply_queue.put(new AltosLine (line));
- }
- line_count = 0;
- line = "";
- }
- } else {
- if (line_bytes == null) {
- line_bytes = new byte[256];
- } else if (line_count == line_bytes.length) {
- byte[] new_line_bytes = new byte[line_count * 2];
- System.arraycopy(line_bytes, 0, new_line_bytes, 0, line_count);
- line_bytes = new_line_bytes;
- }
- line_bytes[line_count] = (byte) c;
- line_count++;
- }
- }