eliminate logging in Connection class
[org.ibex.io.git] / src / org / ibex / io / Stream.java
index d4e0c06..04aef23 100644 (file)
@@ -15,7 +15,6 @@ public class Stream {
 
     protected final In in;
     protected final Out out;
-    private         StringBuffer log = loggingEnabled ? new StringBuffer(16 * 1024) : null;
     private         String newLine = "\r\n";
     private         Stream in_next = null;
 
@@ -28,9 +27,6 @@ public class Stream {
         return this;
     }
 
-    //public static boolean loggingEnabled = "true".equals(System.getProperty("ibex.io.stream.logEnabled", "false"));
-    public static boolean loggingEnabled = true;
-
     public void transcribe(Stream out) { transcribe(out, false); }
     public void transcribe(Stream out, boolean close) {
         try {
@@ -89,86 +85,43 @@ 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);
+        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();
+        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); }
+        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); }
+        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);
+        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);
+        return ret;
     }
 
     public void   unread(String s)                 { in.unread(s); }
@@ -179,10 +132,6 @@ public class Stream {
 
 
     /** dumps the connection log into a file */
-    public  String dumpLog()         { if (log==null) return ""; String ret = log.toString(); log = new StringBuffer(16 * 1024); return ret; }
-    private void  log(String s)      { if(log==null) return; if (!nnl) Log.note("\n[read ] "); Log.note(s + "\n"); nnl=false; if (log != null) log.append(s); }
-    private void  logWrite(String s) { if(log==null) return; if (nnl) Log.note("\n"); Log.note("[write] "+s+"\n"); nnl=false; if (log != null) log.append(s); }
-    private void  log(char c)        { if(log==null) return; if (c == '\r') return; if (!nnl) Log.note("[read ] "); Log.note(c+""); nnl = c != '\n'; if (log != null) log.append(c); }
     private boolean nnl = false;
 
     private static class Out extends BufferedOutputStream {
@@ -330,8 +279,4 @@ public class Stream {
        }
     }
 
-    public static interface Transformer {
-        public Stream transform(Stream in);
-    }
-
 }