+ private static Hashtable blocker = new Hashtable();
+ public static void kill(Thread thread) {
+ Stream block = (Stream)blocker.get(thread);
+ if (block == null) {
+ Log.warn(Stream.class, "thread " + thread + " is not blocked on a stream");
+ } else {
+ Log.warn(Stream.class, "asynchronously closing " + block);
+ block.close();
+ }
+ }
+
+ public char peekc() {
+ Stream old = (Stream)blocker.get(Thread.currentThread());
+ try {
+ blocker.put(Thread.currentThread(), this);
+ flush(); return in.getc(true);
+ } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); }
+ }
+ public char getc() {
+ Stream old = (Stream)blocker.get(Thread.currentThread());
+ try {
+ blocker.put(Thread.currentThread(), this);
+ flush(); char ret = in.getc(false); log(ret); return ret;
+ } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); }
+ }
+ public String readln() {
+ Stream old = (Stream)blocker.get(Thread.currentThread());
+ try {
+ blocker.put(Thread.currentThread(), this);
+ flush(); String s = in.readln(); log(s); log('\n'); return s;
+ } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); }
+ }
+
+ public void print(String s) {
+ Stream old = (Stream)blocker.get(Thread.currentThread());
+ try {
+ blocker.put(Thread.currentThread(), this);
+ logWrite(s);
+ out.write(s);
+ flush();
+ } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); }
+ }
+ public void println(String s) {
+ Stream old = (Stream)blocker.get(Thread.currentThread());
+ try {
+ blocker.put(Thread.currentThread(), this);
+ logWrite(s);
+ out.write(s);
+ out.write(newLine);
+ flush();
+ } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); }
+ }
+ public void flush() {
+ Stream old = (Stream)blocker.get(Thread.currentThread());
+ try {
+ blocker.put(Thread.currentThread(), this);
+ if (out != null) try { out.w.flush(); } catch(IOException e) { ioe(e); }
+ } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); }
+ }