home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 May / PCWK5A99.ISO / Linuxwld / linuxwld.exe / StreamConnector.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-05-31  |  1.9 KB  |  79 lines

  1. import java.io.DataInputStream;
  2. import java.io.IOException;
  3.  
  4. class StreamConnector implements Runnable {
  5.    Streamable stream;
  6.    IRCSession session;
  7.    // $FF: renamed from: t java.lang.Thread
  8.    Thread field_0;
  9.  
  10.    public StreamConnector(DataInputStream var1, IRCSession var2, String var3, int var4) {
  11.       this.session = var2;
  12.       if (var4 > 0) {
  13.          try {
  14.             this.stream = (Streamable)Class.forName("HTTPStream").newInstance();
  15.             this.stream.init(var3, var4);
  16.          } catch (Exception var5) {
  17.             this.stream = null;
  18.          }
  19.       } else {
  20.          this.stream = new IOStream(var1);
  21.       }
  22.  
  23.       this.field_0 = new Thread(this);
  24.       this.field_0.start();
  25.    }
  26.  
  27.    public void send(String var1) throws IOException {
  28.       this.stream.send(var1);
  29.    }
  30.  
  31.    public void run() {
  32.       try {
  33.          while(this.session != null && this.field_0 != null) {
  34.             String var1 = this.stream.receive();
  35.             if (var1 != null) {
  36.                try {
  37.                   this.session.HandleServerMessage(var1);
  38.                } catch (Exception var3) {
  39.                   System.out.println("Warning: Problem handling message:" + var3);
  40.                   ((Throwable)var3).printStackTrace();
  41.                   System.out.println("attempting to continue ...");
  42.                }
  43.                continue;
  44.             }
  45.          }
  46.       } catch (Exception var4) {
  47.          System.out.println("StreamConnector:");
  48.          ((Throwable)var4).printStackTrace();
  49.       }
  50.  
  51.       if (this.session != null) {
  52.          this.session.HandleServerMessage(":client 444 parachat : Network connection closed");
  53.       }
  54.  
  55.       this.disconnect();
  56.    }
  57.  
  58.    public String connect() {
  59.       return this.stream != null ? this.stream.connect() : null;
  60.    }
  61.  
  62.    public void disconnect() {
  63.       try {
  64.          this.session = null;
  65.          if (this.field_0 != null && Thread.currentThread() != this.field_0) {
  66.             this.field_0.stop();
  67.          }
  68.  
  69.          this.field_0 = null;
  70.          if (this.stream != null) {
  71.             this.stream.disconnect();
  72.          }
  73.  
  74.          this.stream = null;
  75.       } catch (Exception var1) {
  76.       }
  77.    }
  78. }
  79.