Пример #1
0
  /**
   * Loads the propertis from the file given the URL
   *
   * @param urlString URL of the file to be used for loading he properties
   * @param p Properties
   */
  private static void loadPropertyFile(Properties p, String urlString) {

    if (urlString == null) {
      spec.harness.Context.out.println("Null urlString");
      return;
    }

    try {
      URL url = new URL(urlString);
      boolean ok = true;

      int ind = urlString.indexOf("http:", 0);
      // spec.harness.Context.out.println( urlString + "=" + ind);
      if (ind == 0) {
        ok = spec.io.FileInputStream.IsURLOk(url);
      }

      if (ok) {
        InputStream str = url.openStream();
        if (str == null) {
          spec.harness.Context.out.println("InputStream in loadPropertyFile is null");
        } else {
          p.load(new BufferedInputStream(str));
        }
      } else {
        spec.harness.Context.out.println("Could not open URL " + urlString);
      }

    } catch (Exception e) {
      spec.harness.Context.out.println("Error loading property file " + urlString + " : " + e);
      //	e.printStackTrace( spec.harness.Context.out );
    }
  }
Пример #2
0
  private void readFromStorableInput(String filename) {
    try {
      URL url = new URL(getCodeBase(), filename);
      InputStream stream = url.openStream();
      StorableInput input = new StorableInput(stream);
      fDrawing.release();

      fDrawing = (Drawing) input.readStorable();
      view().setDrawing(fDrawing);
    } catch (IOException e) {
      initDrawing();
      showStatus("Error:" + e);
    }
  }
Пример #3
0
 private void readFromObjectInput(String filename) {
   try {
     URL url = new URL(getCodeBase(), filename);
     InputStream stream = url.openStream();
     ObjectInput input = new ObjectInputStream(stream);
     fDrawing.release();
     fDrawing = (Drawing) input.readObject();
     view().setDrawing(fDrawing);
   } catch (IOException e) {
     initDrawing();
     showStatus("Error: " + e);
   } catch (ClassNotFoundException e) {
     initDrawing();
     showStatus("Class not found: " + e);
   }
 }
Пример #4
0
  /**
   * Reads GIF file from specified file/URL source (URL assumed if name contains ":/" or "file:")
   *
   * @param name String containing source
   * @return read status code (0 = no errors)
   */
  public int read(String name) {
    status = STATUS_OK;
    try {
      name = name.trim().toLowerCase();
      if ((name.indexOf("file:") >= 0) || (name.indexOf(":/") > 0)) {
        URL url = new URL(name);
        in = new BufferedInputStream(url.openStream());
      } else {
        in = new BufferedInputStream(new FileInputStream(name));
      }
      status = read(in);
    } catch (IOException e) {
      status = STATUS_OPEN_ERROR;
    }

    return status;
  }
Пример #5
0
  public final void run() {
    if (socketthread) {
      socketrun();
      return;
    }
    socketthread = true;
    try {
      boolean flag = false;
      try {
        String s = getParameter("member");
        int i = Integer.parseInt(s);
        if (i == 1) flag = true;
      } catch (Exception _ex) {
      }
      loading = getImage(new URL(getCodeBase(), "loading.jpg"));
      mt = new MediaTracker(this);
      mt.addImage(loading, 0);
      m = MessageDigest.getInstance("SHA");
      System.out.println(link.class);
      String s1 = ".file_store_32/";
      if (s1 == null) return;
      link.uid = getuid(s1);
      link.mainapp = this;
      link.numfile = 0;
      for (int j = 0; j < 14; j++)
        if (flag || !internetname[j].endsWith(".mem")) {
          for (int k = 0; k < 4; k++) {
            if (k == 3) return;
            byte abyte0[] = loadfile(s1 + localname[j], sha[j]);
            if (abyte0 != null) {
              if (j > 0) link.putjag(internetname[j], abyte0);
              break;
            }
            try {
              URL url = new URL(getCodeBase(), internetname[j]);
              DataInputStream datainputstream = new DataInputStream(url.openStream());
              int l = size[j];
              byte abyte1[] = new byte[l];
              for (int i1 = 0; i1 < l; i1 += 1000) {
                int j1 = l - i1;
                if (j1 > 1000) j1 = 1000;
                datainputstream.readFully(abyte1, i1, j1);
                showpercent(nicename[j], (i1 * 100) / l, barpos[j]);
              }

              datainputstream.close();
              FileOutputStream fileoutputstream = new FileOutputStream(s1 + localname[j]);
              fileoutputstream.write(abyte1);
              fileoutputstream.close();
            } catch (Exception _ex) {
            }
          }
        }
      System.out.println(cloader.class);
      cloader cloader1 = new cloader();
      cloader1.zip = new ZipFile(s1 + localname[0]);
      cloader1.link = Class.forName("link");
      inner = new mudclient_Debug();
      loadMacros();
      // inner = (Applet)cloader1.loadClass("mudclient").newInstance();
      inner.init();
      inner.start();
      return;
    } catch (Exception exception) {
      System.out.println(exception + " " + exception.getMessage());
      exception.printStackTrace();
      return;
    }
  }
Пример #6
0
  public void fetchExternalJSLibrary(String targetURLString) {

    final URL targetURL;
    String targetFile = "";
    String s = null;

    InputStream is = null;
    BufferedReader dis = null;

    try {
      // ------------------------------------------------------------//
      // Step 2:  Create the URL.                                   //
      // ------------------------------------------------------------//
      // Note: Put your real URL here, or better yet, read it as a  //
      // command-line arg, or read it from a file.                  //
      // ------------------------------------------------------------//

      targetURL = new URL(targetURLString);

      // ----------------------------------------------//
      // Step 3:  Open an input stream from the url.  //
      // ----------------------------------------------//

      is = targetURL.openStream();

      // -------------------------------------------------------------//
      // Step 4:                                                     //
      // -------------------------------------------------------------//
      // Convert the InputStream to BufferedReader                   //
      // -------------------------------------------------------------//

      dis = new BufferedReader(new InputStreamReader(is));

      // ------------------------------------------------------------//
      // Step 5:                                                    //
      // ------------------------------------------------------------//
      // Now just read each record of the input stream, and print   //
      // it out.  Note that it's assumed that this problem is run   //
      // from a command-line, not from an application or applet.    //
      // ------------------------------------------------------------//

      while ((s = dis.readLine()) != null) {
        targetFile = targetFile + "\n" + s;
      }

      alert(targetFile);
      System.out.println(targetFile);

    } catch (MalformedURLException mue) {

      alert("Ouch - a MalformedURLException happened.");
      System.out.println("Ouch - a MalformedURLException happened.");
      mue.printStackTrace();
      System.exit(1);

    } catch (IOException ioe) {

      alert("Ouch - an IOException happened.");
      System.out.println("Ouch - an IOException happened.");
      ioe.printStackTrace();
      System.exit(1);

    } catch (Exception e) {
      alert("Ouch - Something wrong happened.");
      alert(e.toString());
      alert(e.getMessage());
    } finally {

      // ---------------------------------//
      // Step 6:  Close the InputStream  //
      // ---------------------------------//

      try {
        is.close();
        dis.close();
      } catch (IOException ioe) {
        // just going to ignore this one
      }
    } // end of 'finally' clause
  }