home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / net / Socket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.7 KB  |  229 lines

  1. package java.net;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.security.AccessController;
  7. import java.security.PrivilegedActionException;
  8.  
  9. public class Socket {
  10.    SocketImpl impl;
  11.    private static SocketImplFactory factory;
  12.  
  13.    protected Socket() {
  14.       this.impl = (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
  15.    }
  16.  
  17.    protected Socket(SocketImpl var1) throws SocketException {
  18.       this.impl = var1;
  19.    }
  20.  
  21.    public Socket(String var1, int var2) throws UnknownHostException, IOException {
  22.       this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, true);
  23.    }
  24.  
  25.    public Socket(InetAddress var1, int var2) throws IOException {
  26.       this(var1, var2, (InetAddress)null, 0, true);
  27.    }
  28.  
  29.    public Socket(String var1, int var2, InetAddress var3, int var4) throws IOException {
  30.       this(InetAddress.getByName(var1), var2, var3, var4, true);
  31.    }
  32.  
  33.    public Socket(InetAddress var1, int var2, InetAddress var3, int var4) throws IOException {
  34.       this(var1, var2, var3, var4, true);
  35.    }
  36.  
  37.    public Socket(String var1, int var2, boolean var3) throws IOException {
  38.       this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, var3);
  39.    }
  40.  
  41.    public Socket(InetAddress var1, int var2, boolean var3) throws IOException {
  42.       this(var1, var2, (InetAddress)null, 0, var3);
  43.    }
  44.  
  45.    private Socket(InetAddress var1, int var2, InetAddress var3, int var4, boolean var5) throws IOException {
  46.       this();
  47.       if (var2 >= 0 && var2 <= 65535) {
  48.          if (var4 >= 0 && var4 <= 65535) {
  49.             SecurityManager var6 = System.getSecurityManager();
  50.             if (var6 != null) {
  51.                var6.checkConnect(var1.getHostAddress(), var2);
  52.             }
  53.  
  54.             try {
  55.                this.impl.create(var5);
  56.                if (var3 != null || var4 > 0) {
  57.                   if (var3 == null) {
  58.                      var3 = InetAddress.anyLocalAddress;
  59.                   }
  60.  
  61.                   this.impl.bind(var3, var4);
  62.                }
  63.  
  64.                this.impl.connect(var1, var2);
  65.             } catch (SocketException var8) {
  66.                this.impl.close();
  67.                throw var8;
  68.             }
  69.          } else {
  70.             throw new IllegalArgumentException("port out range:" + var4);
  71.          }
  72.       } else {
  73.          throw new IllegalArgumentException("port out range:" + var2);
  74.       }
  75.    }
  76.  
  77.    public InetAddress getInetAddress() {
  78.       return this.impl.getInetAddress();
  79.    }
  80.  
  81.    public InetAddress getLocalAddress() {
  82.       Object var1 = null;
  83.  
  84.       try {
  85.          var4 = (InetAddress)this.impl.getOption(15);
  86.       } catch (Exception var3) {
  87.          var4 = InetAddress.anyLocalAddress;
  88.       }
  89.  
  90.       return var4;
  91.    }
  92.  
  93.    public int getPort() {
  94.       return this.impl.getPort();
  95.    }
  96.  
  97.    public int getLocalPort() {
  98.       return this.impl.getLocalPort();
  99.    }
  100.  
  101.    public InputStream getInputStream() throws IOException {
  102.       try {
  103.          return (InputStream)AccessController.doPrivileged(new 1(this));
  104.       } catch (PrivilegedActionException var2) {
  105.          throw (IOException)var2.getException();
  106.       }
  107.    }
  108.  
  109.    public OutputStream getOutputStream() throws IOException {
  110.       try {
  111.          return (OutputStream)AccessController.doPrivileged(new 2(this));
  112.       } catch (PrivilegedActionException var2) {
  113.          throw (IOException)var2.getException();
  114.       }
  115.    }
  116.  
  117.    public void setTcpNoDelay(boolean var1) throws SocketException {
  118.       this.impl.setOption(1, new Boolean(var1));
  119.    }
  120.  
  121.    public boolean getTcpNoDelay() throws SocketException {
  122.       return (Boolean)this.impl.getOption(1);
  123.    }
  124.  
  125.    public void setSoLinger(boolean var1, int var2) throws SocketException {
  126.       if (!var1) {
  127.          this.impl.setOption(128, new Boolean(var1));
  128.       } else {
  129.          if (var2 < 0) {
  130.             throw new IllegalArgumentException("invalid value for SO_LINGER");
  131.          }
  132.  
  133.          if (var2 > 65535) {
  134.             var2 = 65535;
  135.          }
  136.  
  137.          this.impl.setOption(128, new Integer(var2));
  138.       }
  139.  
  140.    }
  141.  
  142.    public int getSoLinger() throws SocketException {
  143.       Object var1 = this.impl.getOption(128);
  144.       return var1 instanceof Integer ? (Integer)var1 : -1;
  145.    }
  146.  
  147.    public synchronized void setSoTimeout(int var1) throws SocketException {
  148.       this.impl.setOption(4102, new Integer(var1));
  149.    }
  150.  
  151.    public synchronized int getSoTimeout() throws SocketException {
  152.       Object var1 = this.impl.getOption(4102);
  153.       return var1 instanceof Integer ? (Integer)var1 : 0;
  154.    }
  155.  
  156.    public synchronized void setSendBufferSize(int var1) throws SocketException {
  157.       if (var1 <= 0) {
  158.          throw new IllegalArgumentException("negative send size");
  159.       } else {
  160.          this.impl.setOption(4097, new Integer(var1));
  161.       }
  162.    }
  163.  
  164.    public synchronized int getSendBufferSize() throws SocketException {
  165.       int var1 = 0;
  166.       Object var2 = this.impl.getOption(4097);
  167.       if (var2 instanceof Integer) {
  168.          var1 = (Integer)var2;
  169.       }
  170.  
  171.       return var1;
  172.    }
  173.  
  174.    public synchronized void setReceiveBufferSize(int var1) throws SocketException {
  175.       if (var1 < 0) {
  176.          throw new IllegalArgumentException("invalid receive size");
  177.       } else {
  178.          this.impl.setOption(4098, new Integer(var1));
  179.       }
  180.    }
  181.  
  182.    public synchronized int getReceiveBufferSize() throws SocketException {
  183.       int var1 = 0;
  184.       Object var2 = this.impl.getOption(4098);
  185.       if (var2 instanceof Integer) {
  186.          var1 = (Integer)var2;
  187.       }
  188.  
  189.       return var1;
  190.    }
  191.  
  192.    public void setKeepAlive(boolean var1) throws SocketException {
  193.       this.impl.setOption(8, new Boolean(var1));
  194.    }
  195.  
  196.    public boolean getKeepAlive() throws SocketException {
  197.       return (Boolean)this.impl.getOption(8);
  198.    }
  199.  
  200.    public synchronized void close() throws IOException {
  201.       this.impl.close();
  202.    }
  203.  
  204.    public void shutdownInput() throws IOException {
  205.       this.impl.shutdownInput();
  206.    }
  207.  
  208.    public void shutdownOutput() throws IOException {
  209.       this.impl.shutdownOutput();
  210.    }
  211.  
  212.    public String toString() {
  213.       return "Socket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  214.    }
  215.  
  216.    public static synchronized void setSocketImplFactory(SocketImplFactory var0) throws IOException {
  217.       if (factory != null) {
  218.          throw new SocketException("factory already defined");
  219.       } else {
  220.          SecurityManager var1 = System.getSecurityManager();
  221.          if (var1 != null) {
  222.             var1.checkSetFactory();
  223.          }
  224.  
  225.          factory = var0;
  226.       }
  227.    }
  228. }
  229.