+
+ private static final int buffer_size = 1024;
+
+ private byte[] buffer = new byte[buffer_size];
+ private int buffer_len = 0;
+ private int buffer_off = 0;
+
+ private byte[] debug_chars = new byte[buffer_size];
+ private int debug_off;
+
+ private void debug_input(byte b) {
+ if (b == '\n') {
+ Log.d(TAG, " " + new String(debug_chars, 0, debug_off));
+ debug_off = 0;
+ } else {
+ if (debug_off < buffer_size)
+ debug_chars[debug_off++] = b;
+ }
+ }
+
+ public int getchar() {
+ while (buffer_off == buffer_len) {
+ try {
+ wait_connected();
+ buffer_len = input.read(buffer);
+ buffer_off = 0;
+ } catch (IOException e) {
+ if (D) Log.d(TAG, "getchar IOException");
+ disconnected();
+ return AltosLink.ERROR;
+ } catch (java.lang.InterruptedException e) {
+ if (D) Log.d(TAG, "getchar Interrupted");
+ disconnected();
+ return AltosLink.ERROR;
+ }
+ }
+ if (D)
+ debug_input(buffer[buffer_off]);
+ return buffer[buffer_off++];
+ }
+
+ public void closing() {
+ synchronized(closed_lock) {
+ if (D) Log.d(TAG, "Marked closed true");
+ closed = true;
+ }
+ }
+
+