home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / rmi / transport / StreamRemoteCall.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  4.3 KB  |  176 lines

  1. package sun.rmi.transport;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.io.ObjectInput;
  7. import java.io.ObjectOutput;
  8. import java.io.StreamCorruptedException;
  9. import java.rmi.MarshalException;
  10. import java.rmi.RemoteException;
  11. import java.rmi.UnmarshalException;
  12. import java.rmi.server.LogStream;
  13. import java.rmi.server.ObjID;
  14. import java.rmi.server.RemoteCall;
  15.  
  16. public class StreamRemoteCall implements RemoteCall {
  17.    // $FF: renamed from: in sun.rmi.transport.ConnectionInputStream
  18.    private ConnectionInputStream field_0;
  19.    private ConnectionOutputStream out;
  20.    private Connection conn;
  21.    private boolean resultStarted = false;
  22.  
  23.    public StreamRemoteCall(Connection var1) {
  24.       this.conn = var1;
  25.    }
  26.  
  27.    public StreamRemoteCall(Connection var1, ObjID var2, int var3, long var4) throws RemoteException {
  28.       try {
  29.          this.conn = var1;
  30.          if (Transport.logLevel >= 20) {
  31.             LogStream.log("transport").println("StreamRemoteCall.<init>: write remote call header...");
  32.          }
  33.  
  34.          DataOutputStream var6 = new DataOutputStream(this.conn.getOutputStream());
  35.          var6.writeByte(80);
  36.          this.getOutputStream();
  37.          var2.write(this.out);
  38.          this.out.writeInt(var3);
  39.          this.out.writeLong(var4);
  40.       } catch (IOException var7) {
  41.          throw new MarshalException("Error marshaling call header", var7);
  42.       }
  43.    }
  44.  
  45.    public Connection getConnection() {
  46.       return this.conn;
  47.    }
  48.  
  49.    public ObjectOutput getOutputStream() throws IOException {
  50.       return this.getOutputStream(false);
  51.    }
  52.  
  53.    private ObjectOutput getOutputStream(boolean var1) throws IOException {
  54.       if (this.out == null) {
  55.          if (Transport.logLevel >= 20) {
  56.             LogStream.log("transport").println("StreamRemoteCall.getOutputStream");
  57.          }
  58.  
  59.          this.out = new ConnectionOutputStream(this.conn.getOutputStream(), var1);
  60.       }
  61.  
  62.       return this.out;
  63.    }
  64.  
  65.    public void releaseOutputStream() throws IOException {
  66.       try {
  67.          if (this.out != null) {
  68.             this.out.flush();
  69.             this.out.done(this.conn);
  70.          }
  71.  
  72.          this.conn.releaseOutputStream();
  73.       } finally {
  74.          this.out = null;
  75.       }
  76.  
  77.    }
  78.  
  79.    public ObjectInput getInputStream() throws IOException {
  80.       if (this.field_0 == null) {
  81.          if (Transport.logLevel >= 20) {
  82.             LogStream.log("transport").println("StreamRemoteCall.getInputStream");
  83.          }
  84.  
  85.          this.field_0 = new ConnectionInputStream(this.conn.getInputStream());
  86.       }
  87.  
  88.       return this.field_0;
  89.    }
  90.  
  91.    public void releaseInputStream() throws IOException {
  92.       try {
  93.          if (this.field_0 != null) {
  94.             this.field_0.registerRefs();
  95.             this.field_0.done(this.conn);
  96.          }
  97.  
  98.          this.conn.releaseInputStream();
  99.       } finally {
  100.          this.field_0 = null;
  101.       }
  102.  
  103.    }
  104.  
  105.    public ObjectOutput getResultStream(boolean var1) throws IOException, StreamCorruptedException {
  106.       if (this.resultStarted) {
  107.          throw new StreamCorruptedException("result already in progress");
  108.       } else {
  109.          this.resultStarted = true;
  110.          DataOutputStream var2 = new DataOutputStream(this.conn.getOutputStream());
  111.          var2.writeByte(81);
  112.          this.getOutputStream(true);
  113.          if (var1) {
  114.             this.out.writeByte(1);
  115.          } else {
  116.             this.out.writeByte(2);
  117.          }
  118.  
  119.          this.out.writeID();
  120.          return this.out;
  121.       }
  122.    }
  123.  
  124.    public void executeCall() throws Exception {
  125.       byte var1;
  126.       try {
  127.          this.releaseOutputStream();
  128.          DataInputStream var2 = new DataInputStream(this.conn.getInputStream());
  129.          byte var3 = var2.readByte();
  130.          if (var3 != 81) {
  131.             if (Transport.logLevel >= 10) {
  132.                LogStream.log("transport").println("StreamRemoteCall.executeCall: transport return code invalid: " + var3);
  133.             }
  134.  
  135.             throw new UnmarshalException("Transport return code invalid");
  136.          }
  137.  
  138.          this.getInputStream();
  139.          var1 = this.field_0.readByte();
  140.          this.field_0.readID();
  141.       } catch (UnmarshalException var5) {
  142.          throw var5;
  143.       } catch (IOException var6) {
  144.          throw new UnmarshalException("Error unmarshaling return header");
  145.       }
  146.  
  147.       switch (var1) {
  148.          case 1:
  149.             return;
  150.          case 2:
  151.             Object var7;
  152.             try {
  153.                var7 = this.field_0.readObject();
  154.             } catch (Exception var4) {
  155.                throw new UnmarshalException("Error unmarshaling return", var4);
  156.             }
  157.  
  158.             if (var7 instanceof Exception) {
  159.                throw (Exception)var7;
  160.             }
  161.  
  162.             throw new UnmarshalException("Return type not Exception");
  163.          default:
  164.             if (Transport.logLevel >= 10) {
  165.                LogStream.log("transport").println("StreamRemoteCall.executeCall: return code invalid: " + var1);
  166.             }
  167.  
  168.             throw new UnmarshalException("Return code invalid");
  169.       }
  170.    }
  171.  
  172.    public void done() throws IOException {
  173.       this.releaseInputStream();
  174.    }
  175. }
  176.