home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / guide / rmi / code / XorSocket.java < prev   
Encoding:
Java Source  |  1999-09-19  |  2.8 KB  |  88 lines

  1. /*
  2.  * Copyright (c) 1998, 1999 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  5.  * modify and redistribute this software in source and binary code form,
  6.  * provided that i) this copyright notice and license appear on all copies of
  7.  * the software; and ii) Licensee does not utilize the software in a manner
  8.  * which is disparaging to Sun.
  9.  *
  10.  * This software is provided "AS IS," without a warranty of any kind. ALL
  11.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  12.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  13.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  14.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  15.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  16.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  17.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  18.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  19.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  20.  * POSSIBILITY OF SUCH DAMAGES.
  21.  *
  22.  * This software is not designed or intended for use in on-line control of
  23.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  24.  * the design, construction, operation or maintenance of any nuclear
  25.  * facility. Licensee represents and warrants that it will not use or
  26.  * redistribute the Software for such purposes.
  27.  */
  28.  
  29. package examples.rmisocfac;
  30.  
  31. import java.io.*;
  32. import java.net.*;
  33.  
  34. class XorSocket extends Socket {
  35.   
  36.     /*
  37.      * The pattern used to "encrypt" and "decrypt" each byte sent
  38.      * or received by the socket.
  39.      */
  40.     private byte pattern;
  41.   
  42.     /* The InputStream used by the socket. */
  43.     private InputStream in = null;
  44.   
  45.     /* The OutputStream used by the socket */
  46.     private OutputStream out = null;
  47.   
  48.     /* 
  49.      * Constructor for class XorSocket. 
  50.      */
  51.     public XorSocket(byte pattern)
  52.         throws IOException 
  53.     {
  54.         super();
  55.         this.pattern = pattern;
  56.     }
  57.   
  58.     /* 
  59.      * Constructor for class XorSocket. 
  60.      */
  61.     public XorSocket(String host, int port, byte pattern)
  62.         throws IOException
  63.     {
  64.         super(host, port);
  65.         this.pattern = pattern;
  66.     }
  67.   
  68.     /* 
  69.      * Returns a stream of type XorInputStream. 
  70.      */
  71.     public InputStream getInputStream() throws IOException {
  72.         if (in == null) {
  73.             in = new XorInputStream(super.getInputStream(), pattern);
  74.         }
  75.         return in;
  76.     }
  77.   
  78.     /* 
  79.      *Returns a stream of type XorOutputStream. 
  80.      */
  81.     public OutputStream getOutputStream() throws IOException {
  82.         if (out == null) {
  83.             out = new XorOutputStream(super.getOutputStream(), pattern);
  84.         }
  85.         return out;
  86.     }
  87. }
  88.