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 / net / www / protocol / appletresource / AppletResourceConnection.class (.txt) next >
Encoding:
Java Class File  |  1997-07-08  |  2.3 KB  |  68 lines

  1. package sun.net.www.protocol.appletresource;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import sun.applet.AppletResourceLoader;
  8. import sun.net.www.URLConnection;
  9.  
  10. public class AppletResourceConnection extends URLConnection {
  11.    private static boolean debug;
  12.    private Object resource;
  13.    private String base;
  14.    private String member;
  15.    private URL cachedURL;
  16.  
  17.    protected AppletResourceConnection(URL var1) throws MalformedURLException, IOException {
  18.       super(var1);
  19.       this.debug("AppletResourceConnection(" + var1 + ")");
  20.       String var2 = var1.getFile();
  21.       if (var2.startsWith("/")) {
  22.          var2 = var2.substring(1);
  23.       }
  24.  
  25.       this.base = var2.substring(0, var2.indexOf("/+/"));
  26.       this.member = var2.substring(var2.indexOf("/+/") + 3);
  27.       this.cachedURL = new URL(this.base + this.member);
  28.       this.debug(" base: " + this.base);
  29.       this.debug(" member: " + this.member);
  30.       this.debug(" cachedURL: " + this.cachedURL);
  31.    }
  32.  
  33.    public void connect() throws IOException {
  34.       this.debug("Looking for " + this.cachedURL + " in AppletResourceLoader");
  35.       Object var1 = AppletResourceLoader.getLocalResource(this.cachedURL);
  36.       if (var1 == null) {
  37.          this.debug("Invalid resource name");
  38.          this.resource = null;
  39.       } else {
  40.          this.debug("Found resource");
  41.          this.resource = var1;
  42.       }
  43.    }
  44.  
  45.    public Object getContent() throws IOException {
  46.       if (!super.connected) {
  47.          this.connect();
  48.       }
  49.  
  50.       return this.resource;
  51.    }
  52.  
  53.    public InputStream getInputStream() throws IOException {
  54.       if (!super.connected) {
  55.          this.connect();
  56.       }
  57.  
  58.       return this.resource instanceof InputStream ? (InputStream)this.resource : AppletResourceLoader.getLocalResourceStream(this.cachedURL);
  59.    }
  60.  
  61.    private void debug(String var1) {
  62.       if (debug) {
  63.          System.err.println(var1);
  64.       }
  65.  
  66.    }
  67. }
  68.