void () { final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); myAlarm.addRequest(new Runnable() { public void run() { if(!isClosed()) { myAlarm.addRequest(this, NOTIFY_TEXT_DELAY); checkTextAvailable(); } } }, NOTIFY_TEXT_DELAY); try { while (!isClosed()) { final int c = readNextByte(); if (c == -1) { break; } synchronized (myBuffer) { myBuffer.append((char)c); } if (c == '\n') { // not by '\r' because of possible '\n' checkTextAvailable(); } } } catch (Exception e) { e.printStackTrace(); } finally { try { close(); } finally { Disposer.dispose(this); } } }