Remove compilation errors for MGC code with gc
[IRC.git] / Robust / src / ClassLibrary / SocketInputStream.java
index 43e4ed89e6221c7421125215f930a6c9d9aec30f..807cab6df8408e8beb69a344ae84e48740c026e5 100644 (file)
@@ -1,22 +1,40 @@
 public class SocketInputStream extends InputStream {
-    Socket s;
-    public SocketInputStream(Socket s) {
-       this.s=s;
-    }
+  Socket s;
+  public SocketInputStream(Socket s) {
+    this.s=s;
+  }
 
-    public int read() {
-       byte[] x=new byte[1];
-       int len=s.read(x);
-       if (len<=0)
-           return -1;
-       else return x[0];
-    }
+  public int read() {
+    byte[] x=new byte[1];
+    int len=s.read(x);
+    if (len<=0)
+      return -1;
+    else return x[0];
+  }
 
-    public int read(byte[] b) {
-       return s.read(b);
-    }
+  public int read(byte[] b) {
+    return s.read(b);
+  }
 
-    public void close() {
-       s.close();
+  public int readAll(byte[] b) {
+    int offset=read(b);
+    if (offset<0)
+      return offset;
+    int toread=b.length-offset;
+    while(toread>0) {
+      byte[] t=new byte[toread];
+      int rd=read(t);
+      if (rd<0)
+       return rd;
+      for(int i=0; i<rd; i++)
+       b[i+offset]=t[i];
+      offset+=rd;
+      toread-=rd;
     }
+    return b.length;
+  }
+
+  public void close() {
+    s.close();
+  }
 }