home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / net / www / MimeLauncher.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.2 KB  |  74 lines

  1. /*
  2.  * @(#)MimeLauncher.java    1.11 95/08/22  James Gosling
  3.  * 
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for NON-COMMERCIAL purposes and without fee is hereby
  8.  * granted provided that this copyright notice appears in all copies. Please
  9.  * refer to the file "copyright.html" for further important copyright and
  10.  * licensing information.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
  15.  * OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
  16.  * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR
  17.  * ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.net.www;
  21. import java.net.URL;
  22. import java.io.*;
  23.  
  24. class MimeLauncher extends Thread {
  25.     java.net.URLConnection uc;
  26.     MimeEntry m;
  27.     String GenericTempTemplate;
  28.  
  29.     MimeLauncher (MimeEntry M, java.net.URLConnection uc, String gtt,
  30.           String name) {
  31.     super(name);
  32.     m = M;
  33.     this.uc = uc;
  34.     GenericTempTemplate = gtt;
  35.     }
  36.  
  37.     public void run() {
  38.     try {
  39.         InputStream is = uc.getInputStream();
  40.         String c = m.command;
  41.         int inx = 0;
  42.         boolean substituted = false;
  43.         String ofn = m.TempNameTemplate;
  44.         if (ofn == null)
  45.         ofn = GenericTempTemplate;
  46.         while ((inx = ofn.indexOf("%s")) >= 0)
  47.         ofn = ofn.substring(0, inx) + (System.currentTimeMillis() / 1000) + ofn.substring(inx + 2);
  48.         try {
  49.         OutputStream os = new FileOutputStream(ofn);
  50.         byte buf[] = new byte[2048];
  51.         int i;
  52.         try {
  53.             while ((i = is.read(buf)) >= 0)
  54.             os.write(buf, 0, i);
  55.         } catch(IOException e) {
  56.         }
  57.         os.close();
  58.         } catch(IOException e) {
  59.         }
  60.         is.close();
  61.         while ((inx = c.indexOf("%t")) >= 0)
  62.         c = c.substring(0, inx) + uc.getContentType() + c.substring(inx + 2);
  63.         while ((inx = c.indexOf("%s")) >= 0) {
  64.         c = c.substring(0, inx) + ofn + c.substring(inx + 2);
  65.         substituted = true;
  66.         }
  67.         if (!substituted)
  68.         c = c + " <" + ofn;
  69.         Runtime.getRuntime().exec(c);
  70.     } catch(IOException e) {
  71.     }
  72.     }
  73. }
  74.