Exemplo n.º 1
0
  /**
   * It will call the external dot program, and return the image in binary format.
   *
   * @param dot Source of the graph (in dot language).
   * @return The image of the graph in .gif format.
   */
  private byte[] get_img_stream(File dot) {
    File img;
    byte[] img_stream = null;

    try {
      img = File.createTempFile("graph_", ".gif", new File(this.TEMP_DIR));
      String temp = img.getAbsolutePath();

      Runtime rt = Runtime.getRuntime();
      String cmd = DOT + " -Tgif " + dot.getAbsolutePath() + " -o" + img.getAbsolutePath();
      Process p = rt.exec(cmd);
      p.waitFor();

      FileInputStream in = new FileInputStream(img.getAbsolutePath());
      img_stream = new byte[in.available()];
      in.read(img_stream);
      // Close it if we need to
      if (in != null) in.close();

      if (img.delete() == false)
        System.err.println("Warning: " + img.getAbsolutePath() + " could not be deleted!");
    } catch (java.io.IOException ioe) {
      System.err.println("Error:    in I/O processing of tempfile in dir " + this.TEMP_DIR + "\n");
      System.err.println("       or in calling external command");
      ioe.printStackTrace();
    } catch (java.lang.InterruptedException ie) {
      System.err.println("Error: the execution of the external program was interrupted");
      ie.printStackTrace();
    }

    return img_stream;
  }
Exemplo n.º 2
0
  /** Creates a new instance of TestLoad */
  public void run() {
    //        URL url = new URL(getCodeBase(), "/servlet/ServletName");
    try {
      while (true) {
        URL url = new URL(strURL);

        url.openConnection();
        InputStream in = url.openStream();

        byte[] b = new byte[1000];
        int iTotal = 0;
        int iLen;
        while ((iLen = in.read(b)) != -1) {
          iTotal += iLen;
          this.sleep(READ_DELAY);
        }
        System.out.println("read " + iTotal + " bytes " + this);
        this.sleep(SPIN_DELAY);
        in.close();
      }

    } catch (InterruptedException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 3
0
 /** Creates a new instance of TestLoad */
 public static void main(String[] args) {
   try {
     while (true) {
       TestLoad test = new TestLoad(args);
       test.start();
       Thread.currentThread().sleep(CREATE_DELAY);
     }
   } catch (InterruptedException ex) {
     ex.printStackTrace();
   }
 }
Exemplo n.º 4
0
  /**
   * Method called when the task is executed It continuously check the state of SMS with a frequency
   * of {@link PERIOD}
   */
  @Override
  protected Object doInBackground(Object... params) {

    try {
      Context ctxtApp = (Context) params[0];
      Uri uriSmsInbox = Uri.parse("content://sms/inbox");

      while (true) {
        Cursor cursor = ctxtApp.getContentResolver().query(uriSmsInbox, null, null, null, null);

        /**
         * The SMS charge indicator are reset every time we check the inbox All received SMS are
         * checked, we should consider another way (e.g. consider those received this morning, day)
         * For the unread messages, consider only those received after the last read message
         */
        int newNbAllSms = 0;
        int newNbReadSms = 0;
        int newNbUnReadSms = 0;

        if (cursor.moveToFirst()) {
          do {
            String person = cursor.getString(cursor.getColumnIndex("person"));
            String address = cursor.getString(cursor.getColumnIndex("address"));
            String body = cursor.getString(cursor.getColumnIndex("body"));
            String status = cursor.getString(cursor.getColumnIndex("status"));
            String type = cursor.getString(cursor.getColumnIndex("type"));
            boolean seen = Boolean.getBoolean(cursor.getString(cursor.getColumnIndex("seen")));
            boolean read = Boolean.getBoolean(cursor.getString(cursor.getColumnIndex("read")));
            newNbAllSms += 1;
            newNbReadSms += (read == true ? 1 : 0);
            newNbUnReadSms += (read == false ? 1 : 0);
            Date date = new Date(Long.parseLong(cursor.getString(cursor.getColumnIndex("date"))));
            Log.v(
                TAG,
                date + ": " + person + ", " + address + ", " + body + ", " + status + ", " + type
                    + ", " + seen + ", " + read);
          } while (cursor.moveToNext());
          nbAllSms = nbAllSms == newNbAllSms ? nbAllSms : newNbAllSms;
          nbReadSms = nbReadSms == newNbReadSms ? nbReadSms : newNbReadSms;
          nbUnReadSms = nbUnReadSms == newNbUnReadSms ? nbUnReadSms : newNbUnReadSms;
        }
        cursor.close();
        Thread.sleep(PERIOD);
      }
    } catch (InterruptedException ie) {

      ie.printStackTrace();
    }

    return null;
  }
Exemplo n.º 5
0
  /**
   * It will call the external dot program, and return the image in binary format.
   *
   * @param dot Source of the graph (in dot language).
   * @param type Type of the output image to be produced, e.g.: gif, dot, fig, pdf, ps, svg, png.
   * @return The image of the graph in .gif format.
   */
  private byte[] get_img_stream(File dot, String type) {
    File img;
    byte[] img_stream = null;

    try {
      img = File.createTempFile("graph_", "." + type, new File(GraphViz.TEMP_DIR));
      Runtime rt = Runtime.getRuntime();

      // patch by Mike Chenault
      String[] args = {DOT, "-T" + type, dot.getAbsolutePath(), "-o", img.getAbsolutePath()};

      String strCmd = "";
      for (int m = 0; m < args.length; m++) {
        strCmd = strCmd + " " + args[m];
      }
      System.out.println(strCmd.trim());
      System.out.println(dot.getAbsolutePath());
      System.out.println(img.getAbsolutePath());
      Process p = rt.exec(args);

      p.waitFor();

      FileInputStream in = new FileInputStream(img.getAbsolutePath());
      img_stream = new byte[in.available()];
      in.read(img_stream);
      // Close it if we need to
      if (in != null) in.close();

      if (img.delete() == false)
        System.err.println("Warning: " + img.getAbsolutePath() + " could not be deleted!");
    } catch (java.io.IOException ioe) {
      System.err.println(
          "Error:    in I/O processing of tempfile in dir " + GraphViz.TEMP_DIR + "\n");
      System.err.println("       or in calling external command");
      ioe.printStackTrace();
    } catch (java.lang.InterruptedException ie) {
      System.err.println("Error: the execution of the external program was interrupted");
      ie.printStackTrace();
    }

    return img_stream;
  }
Exemplo n.º 6
0
 /** Run method to start all sub threads that inherit this class. */
 public void run() {
   boolean ready; // Create a boolean to determine if thread is ready.
   do {
     synchronized (datBuff) {
       // If the thread is not ready...
       while (!datBuff.isThready(order)) {
         try {
           datBuff.wait(); // Have it wait..
         } catch (java.lang.InterruptedException e) {
           e.printStackTrace(); // If not throw an error.
           System.exit(1);
         }
       }
       threadIt();
       datBuff.notifyAll(); // Notify all other threads to check if they are ready.
       ready = datBuff.getThreadStat(order); // Set the status of current thread.
     }
   } while (!ready);
   if (datBuff.getThreadStat(3)) {
     System.exit(0); // If so exit the program.
   }
 }