X-Git-Url: http://git.megacz.com/?p=org.ibex.io.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fio%2FStream.java;h=1d03c204c061058a8d45b0bf1da61d54d7f4e97b;hp=d4e0c06da61f7b80f0b134c6237871c6817ae5ef;hb=7e42d1f8cb29c10f7b3b3e8679e9f1643c948bda;hpb=fb36cd8efcf7e222502a59f33423b1efefd370e2 diff --git a/src/org/ibex/io/Stream.java b/src/org/ibex/io/Stream.java index d4e0c06..1d03c20 100644 --- a/src/org/ibex/io/Stream.java +++ b/src/org/ibex/io/Stream.java @@ -89,86 +89,51 @@ public class Stream { public static class Closed extends StreamException { public Closed(String s) { super(s); } } - 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); } + flush(); + return in.getc(true); } 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); } + flush(); + char ret = in.getc(false); + log(ret); + return ret; } 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); } + flush(); + String s = in.readln(); + log(s); + log('\n'); + return s; } 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); } + logWrite(s); + out.write(s); + flush(); } public void println(String s) { - Stream old = (Stream)blocker.get(Thread.currentThread()); - try { - blocker.put(Thread.currentThread(), this); - logWrite(s); - logWrite(newLine); - out.write(s); - out.write(newLine); - flush(); - } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); } + logWrite(s); + logWrite(newLine); + out.write(s); + out.write(newLine); + flush(); } 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); } + if (out != null) try { out.w.flush(); } catch(IOException e) { ioe(e); } } public int read(byte[] b, int off, int len) { - Stream old = (Stream)blocker.get(Thread.currentThread()); - try { - blocker.put(Thread.currentThread(), this); - flush(); - int ret = in.readBytes(b, off, len); - if (log != null) log("\n[read " + ret + " bytes of binary data ]\n"); - nnl = false; - return ret; - } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); } + flush(); + int ret = in.readBytes(b, off, len); + if (log != null) log("\n[read " + ret + " bytes of binary data ]\n"); + nnl = false; + return ret; } public int read(char[] c, int off, int len) { - Stream old = (Stream)blocker.get(Thread.currentThread()); - try { - blocker.put(Thread.currentThread(), this); - flush(); - int ret = in.read(c, off, len); - if (log != null && ret != -1) log(new String(c, off, ret)); - return ret; - } finally { if (old == null) blocker.remove(Thread.currentThread()); else blocker.put(Thread.currentThread(), old); } + flush(); + int ret = in.read(c, off, len); + if (log != null && ret != -1) log(new String(c, off, ret)); + return ret; } public void unread(String s) { in.unread(s); }