/** Modified by Gabriele Bianchi 04/01/2006 */
  public void run() {
    StringBuffer connectorStringBuffer;
    if (Datas.isSSL) {
      connectorStringBuffer = new StringBuffer("ssl://");
    } else {
      connectorStringBuffer = new StringBuffer("socket://");
    }
    connectorStringBuffer.append(_hostname);
    connectorStringBuffer.append(":");
    connectorStringBuffer.append(_port);
    connectorStringBuffer.append("");

    String connectorString = connectorStringBuffer.toString().trim();
    System.out.println(connectorString);
    try {
      if (Datas.isSSL) {
        connection = (SecureConnection) Connector.open(connectorString);
      } else {
        connection = (StreamConnection) /*Connector.open*/ getConnectionForRequest(connectorString);
      }
      if (connection != null) {
        SocketConnection sc = (SocketConnection) connection;
        sc.setSocketOption(SocketConnection.KEEPALIVE, 2);
      }

      _cm.notifyConnect(connection, this.openInputStream(), this.openOutputStream());
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Connessione non riuscita:" + e.getMessage());
      _cm.notifyNoConnectionOn("I can't connect, server is unreachable");
      DebugStorage.getInstance().Log(0, "Can't connect, server is unreachable", e);
    }

    return;
  }
Esempio n. 2
0
 int getLineLength(int y) {
   try {
     return ((StringBuffer) vectorLines.elementAt(y)).length();
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in getLineLength()");
     return 0;
   }
 }
Esempio n. 3
0
 StringBuffer getLine(int y) {
   try {
     return (StringBuffer) vectorLines.elementAt(y);
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in getLine()");
     return new StringBuffer("");
   }
 }
Esempio n. 4
0
 boolean addNewLine(int y) {
   try {
     vectorLines.insertElementAt(new StringBuffer(""), y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString());
     return false;
   }
 }
Esempio n. 5
0
 boolean removeLine(int y) {
   try {
     vectorLines.removeElementAt(y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in removeLine()");
     return false;
   }
 }
Esempio n. 6
0
 boolean setLine(int y, StringBuffer stringBuffer) {
   try {
     vectorLines.setElementAt(stringBuffer, y);
     return true;
   } catch (Exception ex) {
     System.out.println(ex.toString() + " in setLine()");
     return false;
   }
 }
Esempio n. 7
0
 public void run() {
   while (true) {
     checkTimestamps();
     repaint();
     try {
       synchronized (this) {
         wait(50L);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Esempio n. 8
0
  boolean copyLine(int sourceY, int destinationY) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(sourceY);
      // setLine
      vectorLines.setElementAt(currentLine, destinationY);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in copyLine()");
      return false;
    }
  }
Esempio n. 9
0
  boolean removeFromLine(int xFrom, int xTo, int y) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.delete(xFrom, xTo);
      // setLine
      vectorLines.setElementAt(currentLine, y);
      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in removeFromLine()");
      return false;
    }
  }
Esempio n. 10
0
  boolean updateToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.setCharAt(x - 1, ch);
      // setLine
      vectorLines.setElementAt(currentLine, y);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in updateToLine()");
      return false;
    }
  }
Esempio n. 11
0
  /** Save the URL setting the user entered in to the urlTextBox. */
  private void saveURLSetting() {
    String temp;
    Exception ex;

    temp = urlTextBox.getString();

    ex = GraphicalInstaller.saveSettings(temp, MIDletSuite.INTERNAL_SUITE_ID);
    if (ex != null) {
      displayException(Resource.getString(ResourceConstants.EXCEPTION), ex.toString());
      return;
    }

    defaultInstallListUrl = temp;

    displaySuccessMessage(Resource.getString(ResourceConstants.AMS_MGR_SAVED));
  }
Esempio n. 12
0
  boolean shiftDown(int y) {
    try {
      addNewLine(getLinesCount() + 1 - 1);

      // tricky! -1 because of beginning from 0, -1 because next line, -1 because getLinesCount() is
      // already updated (+1)
      for (int sourceY = getLinesCount() - 2; sourceY >= y; sourceY--) // -1
      {
        copyLine(sourceY, sourceY + 1);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in shiftDown()");
      return false;
    }
  }
Esempio n. 13
0
  /** Ask the user for the URL. */
  private void getUrl() {
    try {
      if (urlTextBox == null) {
        urlTextBox =
            new TextBox(
                Resource.getString(ResourceConstants.AMS_DISC_APP_WEBSITE_INSTALL),
                defaultInstallListUrl,
                1024,
                TextField.ANY);
        urlTextBox.addCommand(endCmd);
        urlTextBox.addCommand(saveCmd);
        urlTextBox.addCommand(discoverCmd);
        urlTextBox.setCommandListener(this);
      }

      display.setCurrent(urlTextBox);
    } catch (Exception ex) {
      displayException(Resource.getString(ResourceConstants.EXCEPTION), ex.toString());
    }
  }
Esempio n. 14
0
  boolean addToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.insert(x, ch);

      if (vectorLines.size() < y) {
        vectorLines.addElement(currentLine);
      } else {
        // setLine
        vectorLines.setElementAt(currentLine, y);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in addToLine()");
      return false;
    }
  }
Esempio n. 15
0
  /**
   * Install a suite.
   *
   * @param selectedSuite index into the installList
   */
  private void installSuite(int selectedSuite) {
    MIDletStateHandler midletStateHandler = MIDletStateHandler.getMidletStateHandler();
    MIDletSuite midletSuite = midletStateHandler.getMIDletSuite();
    SuiteDownloadInfo suite;
    String displayName;

    suite = (SuiteDownloadInfo) installList.elementAt(selectedSuite);

    midletSuite.setTempProperty(null, "arg-0", "I");
    midletSuite.setTempProperty(null, "arg-1", suite.url);
    midletSuite.setTempProperty(null, "arg-2", suite.label);

    displayName = Resource.getString(ResourceConstants.INSTALL_APPLICATION);
    try {
      midletStateHandler.startMIDlet("com.sun.midp.installer.GraphicalInstaller", displayName);
      /*
       * Give the create MIDlet notification 1 second to get to
       * AMS.
       */
      Thread.sleep(1000);
      notifyDestroyed();
    } catch (Exception ex) {
      StringBuffer sb = new StringBuffer();

      sb.append(displayName);
      sb.append("\n");
      sb.append(Resource.getString(ResourceConstants.ERROR));
      sb.append(": ");
      sb.append(ex.toString());

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.AMS_CANNOT_START),
              sb.toString(),
              null,
              AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      display.setCurrent(a, urlTextBox);
    }
  }
Esempio n. 16
0
  private String getContent(String url) {
    HttpConnection httemp = null;
    InputStream istemp = null;
    String content = "";

    try {
      httemp = (HttpConnection) Connector.open(url);
      httemp.setRequestProperty("Connection", "cl" + "ose");
      if (HttpConnection.HTTP_OK != httemp.getResponseCode()) {
        throw new IOException();
      }

      istemp = httemp.openInputStream();
      int length = (int) httemp.getLength();
      if (-1 != length) {
        byte[] bytes = new byte[length];
        istemp.read(bytes);
        content = new String(bytes);

      } else {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        while (true) {
          int ch = istemp.read();
          if (-1 == ch) break;
          bytes.write(ch);
        }
        content = new String(bytes.toByteArray());
        bytes.close();
      }

    } catch (Exception e) {
      content = "Error: " + e.getMessage();
    }
    try {
      httemp.close();
      istemp.close();
    } catch (Exception e) {
    }
    return StringConvertor.removeCr(content);
  }
 private void startSession() {
   SipClientConnection scc = null;
   try {
     // <i><b>start a listener for incoming requests</b></i>
     startListener();
     // <i><b>open SIP connection with remote user</b></i>
     scc = (SipClientConnection) Connector.open(address.getString());
     scc.setListener(this);
     // <i><b>initialize INVITE request</b></i>
     scc.initRequest("INVITE", scn);
     scc.setHeader("Content-Length", "" + sdp.length());
     scc.setHeader("Content-Type", "application/sdp");
     OutputStream os = scc.openContentOutputStream();
     os.write(sdp.getBytes());
     os.close(); // <i><b>close and send</b></i>
     str = new StringItem("Inviting... ", scc.getHeader("To"));
     form.append(str);
   } catch (Exception ex) {
     ex.printStackTrace();
     // <i><b>handle IOException</b></i>
   }
 }
Esempio n. 18
0
  boolean divideLine(int x, int y) // fire <=> enter + insert when # pressed
      {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      String newLine = currentLine.toString().substring(x, currentLine.toString().length());

      currentLine.delete(x, currentLine.length());
      // setLine
      vectorLines.setElementAt(currentLine, y);

      if (shiftDown(y)) {
        vectorLines.setElementAt(new StringBuffer(newLine), y + 1);
      }

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in divideLine()");
      return false;
    }
  }
  public void run_0420() {
    FileConnection conn1 = null;
    int counter = 0;
    try {
      // Make a connection to the new file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test040/new042File.txt", Connector.READ_WRITE);
      counter = 1;
      System.out.println(" run_0420: counter = 1 ");
      if (conn1.exists()) throw new TestFailedException();
      counter = 2;
      System.out.println(" run_0420: counter = 2 ");
      conn1.create();
      counter = 3;
      System.out.println(" run_0420: counter = 3 ");
      OutputStream stream = conn1.openOutputStream();
      counter = 4;
      System.out.println(" run_0420: counter = 4 ");
      byte[] byteArray1 = new byte[50];
      for (int i = 0; i < byteArray1.length; ++i) byteArray1[i] = 55;
      counter = 5;
      System.out.println(" run_0420: counter = 5 ");
      stream.write(byteArray1);
      stream.close();
      counter = 6;
      System.out.println(" run_0420: counter = 6 ");
      // Re-open an OutputStream.
      stream = conn1.openOutputStream(conn1.fileSize());
      counter = 7;
      System.out.println(" run_0420: counter = 7 ");
      for (int i = 0; i < byteArray1.length; ++i) byteArray1[i] = 56;
      conn1.close();
      counter = 8;
      stream.write(byteArray1);
      counter = 9;
      stream.close();

      System.out.println(" Going to second part of run_0420");

      // Re-open a connection.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test040/new042File.txt", Connector.READ_WRITE);
      counter = 10;
      System.out.println(" run_0420: counter = 10 ");
      if (!conn1.exists()) throw new TestFailedException();
      counter = 11;
      System.out.println(" run_0420: counter = 11 ");
      InputStream inStream = conn1.openInputStream();
      counter = 12;
      System.out.println(" run_0420: counter = 12 ");
      byte[] byteArray2 = new byte[110];
      int retValue = inStream.read(byteArray2);
      if (retValue != 100) throw new TestFailedException("retValue: " + retValue);
      counter = 13;
      System.out.println(" run_0420: counter = 13 ");
      for (int i = 0; i < retValue; ++i) {
        if (i < 50) {
          if (byteArray2[i] != 55)
            throw new TestFailedException("i: " + i + " byteArray2[i]: " + byteArray2[i]);
        } else if (i > 49) {
          if (byteArray2[i] != 56)
            throw new TestFailedException("i: " + i + " byteArray2[i]: " + byteArray2[i]);
        }
      } // end for
      counter = 14;
      conn1.close();
      inStream.close();

      assertTrue(" run_0420() ok ", true);
    } catch (Exception ex) {
      append(ex.toString());
      append("TEST FAILED!!! Case: run_0420() counter: " + counter + "\n");
      assertTrue(" run_0420() FAILED!!! Counter: " + counter, false);
    }
  } // end run_0420()
Esempio n. 20
0
  /**
   * Task execution code: <br>
   * ---------- <br>
   * Performed operations: <br>
   *
   * <ul type="disc">
   *   <li>Add alarm to position strings, if necessary;
   *   <li>Send string;
   *   <li>Check the number of sent strings.
   * </ul>
   */
  public void run() {

    list = new BCListenerCustom();
    list.addInfoStato(infoS);
    BearerControl.addListener(list);

    while (!infoS.isCloseUDPSocketTask()) {

      // if(false){
      if ((infoS.getInfoFileString(TrkState).equals("ON")
              || (infoS.getInfoFileString(TrkState)).equalsIgnoreCase("ON,FMS"))
          && infoS.getInfoFileString(GPRSProtocol).equals("UDP")
          && ((infoS.getInfoFileInt(TrkIN) != infoS.getInfoFileInt(TrkOUT))
              || !infoS.getDataRAM().equals(""))) {

        exitTRKON = false;

        try {

          // Indicates if GPRS SOCKET is ACTIVE
          // System.out.println("TT*UDPSocketTask: START");
          infoS.setIfsocketAttivo(true);
          destAddressUDP =
              "datagram://"
                  + infoS.getInfoFileString(DestHost)
                  + ":"
                  + infoS.getInfoFileString(DestPort);

          /*
           * Once this task has been started, it is completely
           * finished before proceeding to a re-use, even if the
           * timeout expires (so there may be a FIX GPRS timeout
           * expired!)
           */
          try {
            try {
              while (!InfoStato.getCoda()) Thread.sleep(1L);
            } catch (InterruptedException e) {
            }

            if (infoS.getInfoFileInt(TrkIN) == infoS.getInfoFileInt(TrkOUT)) {
              outText = infoS.getDataRAM();
              ram = true;
            } else {
              ram = false;
              temp = infoS.getInfoFileInt("TrkOUT");
              System.out.println("TT*UDPSocketTask: pointer out - " + temp);
              if ((temp >= codaSize) || (temp < 0)) temp = 0;
              outText = infoS.getRecord(temp);
              new LogError("TT*UDPSocketTask: pointer out - " + temp + " " + outText);
              System.out.println("TT*UDPSocketTask: data in queue: " + outText);
            }

            System.out.println("TT*UDPSocketTask: string to send through GPRS:\r\n" + this.outText);

            ctrlSpeed = infoS.getSpeedForTrk();
            if (debug_speed) {
              ctrlSpeed = infoS.getSpeedGree();
              System.out.println("SPEED " + ctrlSpeed);
            }
            try {
              val_insensibgps = Integer.parseInt(infoS.getInfoFileString(InsensibilitaGPS));
            } catch (NumberFormatException e) {
              val_insensibgps = 0;
            }
            // new LogError("Actual speed: " + ctrlSpeed + ". Val insens: " + val_insensibgps);

            if (ram) {

              // System.out.println("ACTUAL SPEED: " + this.ctrlSpeed);
              // System.out.println("outText.indexOf(ALARM) " + (this.outText.indexOf("ALARM") >
              // 0));
              // System.out.println("outText.indexOf(ALIVE) " + (this.outText.indexOf("ALIVE") >
              // 0));
              // System.out.println("SPEED LIMIT: " + this.val_insensibgps);
              // System.out.println("PREVIOUS MESSAGE IS ALIVE: " + this.infoS.getPreAlive());
              // System.out.println("SPEED LIMIT: " + this.val_insensibgps);
              // System.out.println("PREVIOUS SPEED: " + this.infoS.getPreSpeedDFS());

              if (this.ctrlSpeed > this.val_insensibgps) {
                System.out.println("Speed check ok.");
                infoS.settrasmetti(true);
                if (this.infoS.getInvioStop()) {
                  infoS.setApriGPRS(true);
                }
                infoS.setInvioStop(false);
              } else {
                if ((outText.indexOf("ALARM") > 0) || (outText.indexOf("ALIVE") > 0)) {
                  System.out.println("Alarm");
                  infoS.settrasmetti(true);
                  infoS.setApriGPRS(true);
                } else {

                  if ((!infoS.getPreAlive())
                      && (ctrlSpeed <= val_insensibgps)
                      && (infoS.getPreSpeedDFS() > val_insensibgps)) {

                    System.out.println(
                        "Speed check less then insensitivity, previous speed is greater");
                    infoS.settrasmetti(true);
                    if (infoS.getInvioStop() == true) {
                      infoS.setApriGPRS(true);
                    }
                    infoS.setInvioStop(false);

                  } else {

                    System.out.println("Speed check failed.");
                    if (infoS.getInvioStop() == false) {
                      System.out.println("Send stop coordinate.");
                      infoS.settrasmetti(true);
                      infoS.setInvioStop(true);
                      infoS.setChiudiGPRS(true);

                      // new LogError("Send stop.");
                    }
                  }
                }
              }
              if (this.outText.indexOf("ALIVE") > 0) {
                System.out.println("ALIVE MESSAGE");
                infoS.setPreAlive(true);
              } else {
                infoS.setPreAlive(false);
                System.out.println("NO ALIVE MESSAGE");
              }
            } else {
              // new LogError("From store.");

              infoS.settrasmetti(true);

              infoS.setChiudiGPRS(false);
            }

            // new LogError("Transmission status: " + infoS.gettrasmetti());

            if (infoS.gettrasmetti() == true) {

              infoS.settrasmetti(false);

              if (infoS.getApriGPRS() == true) {

                close = false;
                infoS.setTRKstate(true);
                try {
                  semAT.getCoin(5);
                  infoS.setATexec(true);
                  mbox2.write("at^smong\r");
                  while (infoS.getATexec()) {
                    Thread.sleep(whileSleep);
                  }
                  infoS.setATexec(true);
                  mbox2.write("at+cgatt=1\r");
                  while (infoS.getATexec()) {
                    Thread.sleep(whileSleep);
                  }
                  semAT.putCoin();
                } catch (Exception e) {
                }

                // Open GPRS Channel
                try {
                  udpConn = (UDPDatagramConnection) Connector.open(destAddressUDP);
                } catch (Exception e) {
                  System.out.println("TT*UDPSocketTask: Connector.open");
                }
                infoS.setApriGPRS(false);
              }

              try {
                // mem2 = r.freeMemory();
                // System.out.println("Free memory after allocation: " + mem2);
                if ((outText == null) || (outText.indexOf("null") >= 0)) {
                  outText =
                      infoS.getInfoFileString(Header)
                          + ","
                          + infoS.getInfoFileString(IDtraker)
                          + defaultGPS
                          + ",<ERROR>*00";
                  buff = outText.getBytes();
                }
                System.out.println("OPEN DATAGRAM");
                System.out.println(outText);
                dgram = udpConn.newDatagram(outText.length());
                buff = new byte[outText.length()];
                System.out.println("SEND DATAGRAM");
                buff = outText.getBytes();
                new LogError("outText = " + outText);
                dgram.setData(buff, 0, buff.length);
                udpConn.send(dgram);
                int gprsCount = 0;
                answer = "";
                String ack = infoS.getInfoFileString(Ackn);
                if (!infoS.getInfoFileString(Ackn).equals("")) {
                  while (true) {
                    dgram.reset();
                    dgram.setLength(infoS.getInfoFileString(Ackn).length() + 1);
                    udpConn.receive(dgram);
                    byte[] data = dgram.getData();
                    answer = new String(data);
                    answer = answer.substring(0, ack.length());
                    if (debug) {
                      System.out.println("ACK: " + answer);
                    }
                    if (answer.equals(ack)) {
                      new LogError("ACK");
                      if (debug) System.out.println("ACK RECEIVED");
                      break;
                    } else {
                      if (debug) System.out.println("WAITING ACK");
                      try {
                        Thread.sleep(1000);
                      } catch (InterruptedException e) {
                      }
                      gprsCount++;
                    }
                    if (gprsCount > 15) {
                      new LogError("NACK");
                      infoS.setReboot();
                      errorSent = true;
                      break;
                    }
                  }
                }

              } catch (Exception err) {
                System.out.println("TT*UDPSocketTask: Exception err");
                new LogError("TT*UDPSocketTask: Exception during out text" + err.getMessage());
                infoS.setReboot();
                errorSent = true;
                break;
              }
              // new LogError(outText);
              if (debug) System.out.println(outText);

              if (infoS.getChiudiGPRS() == true) {

                infoS.setTRKstate(false);
                try {
                  System.out.println("TT*UDPSocketTask: close UDP");
                  udpConn.close();
                } catch (NullPointerException e) {
                  infoS.setChiudiGPRS(false);
                }
                infoS.setChiudiGPRS(false);
              }
            }

            System.out.println("BEARER: " + infoS.getGprsState());
            if (!infoS.getGprsState()) {
              errorSent = true;
              System.out.println("BEARER ERROR");
              new LogError("BEARER ERROR");
            }

            if (ram) {
              if (!errorSent) {
                infoS.setDataRAM("");
              }
            } else {
              if (!errorSent) {
                temp++;
                if (temp >= codaSize || temp < 0) temp = 0;
                infoS.setInfoFileInt(TrkOUT, "" + temp);
                file.setImpostazione(TrkOUT, "" + temp);
                InfoStato.getFile();
                file.writeSettings();
                InfoStato.freeFile();
              }
              errorSent = false;
            }
            InfoStato.freeCoda();

            infoS.setIfsocketAttivo(false);
            Thread.sleep(100);
            if (errorSent) {
              close = true;
              semAT.putCoin(); // release AT interface
              infoS.setIfsocketAttivo(false);
              infoS.setApriGPRS(false);
              infoS.setChiudiGPRS(false);
            }
            // r.gc(); // request garbage collection

            // mem2 = r.freeMemory();
            // System.out.println("Free memory after collecting" + " discarded Integers: " + mem2);

          } catch (IOException e) {
            close = true;
            String msgExcept = e.getMessage();
            System.out.println("TT*UDPSocketTask: exception: " + msgExcept);

            // new LogError("SocketGPRStask IOException: " + e);
            infoS.setIfsocketAttivo(false);

            infoS.setApriGPRS(false);
            infoS.setChiudiGPRS(false);

          } catch (EmptyStackException e) {
            close = true;
            // System.out.println("exception: " + e.getMessage());
            e.printStackTrace();

            // new LogError("SocketGPRStask EmptyStackException");
            infoS.setIfsocketAttivo(false);

            infoS.setApriGPRS(false);
            infoS.setChiudiGPRS(false);
          } // catch

        } catch (Exception e) {
          close = true;
          // new LogError("SocketGPRSTask generic Exception");
          infoS.setIfsocketAttivo(false);

          infoS.setApriGPRS(false);
          infoS.setChiudiGPRS(false);
        }

        if (close) {

          try {
            semAT.getCoin(5);
            infoS.setATexec(true);
            mbox2.write("at^smong\r");
            while (infoS.getATexec()) {
              Thread.sleep(whileSleep);
            }
            semAT.putCoin();
          } catch (Exception e) {
          }

          try {
            // System.out.println("***************CLOSE******************");
            try {
              udpConn.close();
            } catch (NullPointerException e) {

            }
            // System.out.println("***************CLOSED******************");

            infoS.setTRKstate(false);
            infoS.setEnableCSD(true);

            semAT.getCoin(5);
            // Close GPRS channel
            // System.out.println("SocketGPRSTask: KILL GPRS");
            infoS.setATexec(true);
            mbox2.write("at+cgatt=0\r");
            while (infoS.getATexec()) {
              Thread.sleep(whileSleep);
            }

            semAT.putCoin();

            Thread.sleep(5000);
          } catch (InterruptedException e) {

          } catch (IOException e) {

          } catch (Exception e) {

          }
          System.out.println("WAIT - DISCONNECT GPRS");
          for (countDownException = 0; countDownException < 100; countDownException++) {
            if (infoS.isCloseUDPSocketTask()) break;
            try {
              Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
          }
          infoS.setApriGPRS(true);
        }
      } else {

        try {
          if (infoS.getInfoFileString(TrkState).equals("OFF")) {

            infoS.setTRKstate(false);
            infoS.setEnableCSD(true);
            semAT.putCoin(); // release AT interface
            try {
              semAT.getCoin(5);
              // Close GPRS channel
              // System.out.println("SocketGPRSTask: TRK OFF KILL GPRS");
              infoS.setATexec(true);
              mbox2.write("at+cgatt=0\r");
              while (infoS.getATexec()) {
                Thread.sleep(whileSleep);
              }
              semAT.putCoin();
            } catch (InterruptedException e) {
            }
          }
          Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
      }
    } // while
  } // run
  public void run_1720() {
    FileConnection conn1 = null;
    int counter = 0;
    try {
      // 1 Opening a file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test170/readOnly.txt", Connector.READ_WRITE);
      counter = 1;
      InputStream stream = conn1.openInputStream();
      counter = 3;
      byte[] byteArray1 = new byte[500];
      int retValue = stream.read(byteArray1);
      counter = 4;
      if (retValue != 500) throw new TestFailedException("retValue: " + retValue);
      counter = 5;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray1[i] != 56)
          throw new TestFailedException("byteArray1[i]: " + byteArray1[i] + "i: " + i);
      }
      conn1.setHidden(true);
      conn1.setHidden(true);
      counter = 6;
      boolean hiddenFlag = conn1.isHidden();
      if (hiddenFlag == false) throw new TestFailedException();
      counter = 7;
      try {
        stream.read(byteArray1);
        throw new TestFailedException();
      } catch (IOException ex) {
      }

      // Re-opening a InputStream.
      stream = conn1.openInputStream();
      counter = 71;
      byte[] byteArray12 = new byte[1601];
      retValue = stream.read(byteArray12);
      counter = 72;
      if (retValue != 1600) throw new TestFailedException("retValue: " + retValue);
      counter = 73;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray12[i] != 56)
          throw new TestFailedException("byteArray12[i]: " + byteArray12[i] + "i: " + i);
      }
      stream.close();
      conn1.close();

      // 2 Re-open a file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test170/readOnly.txt", Connector.READ_WRITE);
      counter = 8;
      stream = conn1.openInputStream();
      counter = 9;
      byteArray1 = new byte[500];
      retValue = stream.read(byteArray1);
      counter = 10;
      if (retValue != 500) throw new TestFailedException("retValue: " + retValue);
      counter = 11;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray1[i] != 56)
          throw new TestFailedException("byteArray1[i]: " + byteArray1[i] + "i: " + i);
      }
      counter = 12;
      conn1.setHidden(true);
      byte[] byteArray2 = new byte[1200];
      retValue = stream.read(byteArray2);
      counter = 13;
      if (retValue != 1100) throw new TestFailedException("retValue: " + retValue);
      counter = 14;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray2[i] != 56)
          throw new TestFailedException("byteArray2[i]: " + byteArray2[i] + "i: " + i);
      }
      stream.close();
      conn1.close();

      // 3 Re-open a file.
      conn1 =
          (FileConnection)
              Connector.open(
                  "file:///" + iRoot + "mainTestDir/test170/readOnly.txt", Connector.READ_WRITE);
      stream = conn1.openInputStream();
      counter = 15;
      byteArray1 = new byte[500];
      retValue = stream.read(byteArray1);
      counter = 16;
      if (retValue != 500) throw new TestFailedException("retValue: " + retValue);
      counter = 17;
      for (int i = 0; i < retValue; ++i) {
        if (byteArray1[i] != 56)
          throw new TestFailedException("byteArray1[i]: " + byteArray1[i] + "i: " + i);
      }
      counter = 18;
      System.out.println(" Test 1720: COunter 8");
      conn1.setHidden(false);
      hiddenFlag = conn1.isHidden();
      if (hiddenFlag == true) throw new TestFailedException();
      counter = 19;
      try {
        stream.read(byteArray1);
        throw new TestFailedException();
      } catch (IOException ex) {
      }
      stream.close();
      conn1.close();

      assertTrue(" run_1720() ok ", true);
    } catch (Exception ex) {
      append(ex.toString());
      append("TEST FAILED!!! Case: run_1720() counter: " + counter + "\n");
      assertTrue(" run_1720() FAILED!!! Counter: " + counter, false);
    }
  }
Esempio n. 22
0
    /**
     * Get the list of suites for the user to install. The suites that are listed are the links on a
     * web page that end with .jad.
     */
    public void run() {
      StreamConnection conn = null;
      InputStreamReader in = null;
      String errorMessage;
      long startTime;

      startTime = System.currentTimeMillis();

      try {
        parent.displayProgressForm(
            Resource.getString(ResourceConstants.AMS_DISC_APP_GET_INSTALL_LIST),
            "",
            url,
            0,
            Resource.getString(ResourceConstants.AMS_GRA_INTLR_CONN_GAUGE_LABEL));
        conn = (StreamConnection) Connector.open(url, Connector.READ);
        in = new InputStreamReader(conn.openInputStream());
        try {
          parent.updateProgressForm(
              "", 0, Resource.getString(ResourceConstants.AMS_DISC_APP_GAUGE_LABEL_DOWNLOAD));

          parent.installList = SuiteDownloadInfo.getDownloadInfoFromPage(in);

          if (parent.installList.size() > 0) {
            parent.installListBox =
                new List(
                    Resource.getString(ResourceConstants.AMS_DISC_APP_SELECT_INSTALL),
                    Choice.IMPLICIT);

            // Add each suite
            for (int i = 0; i < parent.installList.size(); i++) {
              SuiteDownloadInfo suite = (SuiteDownloadInfo) installList.elementAt(i);
              parent.installListBox.append(suite.label, (Image) null);
            }

            parent.installListBox.addCommand(parent.backCmd);
            parent.installListBox.addCommand(parent.installCmd);
            parent.installListBox.setCommandListener(parent);

            /*
             * We need to prevent "flashing" on fast development
             * platforms.
             */
            while (System.currentTimeMillis() - parent.lastDisplayChange
                < GraphicalInstaller.ALERT_TIMEOUT) ;

            parent.display.setCurrent(parent.installListBox);
            return;
          }

          errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CHECK_URL_MSG);
        } catch (IllegalArgumentException ex) {
          errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_URL_FORMAT_MSG);
        } catch (Exception ex) {
          errorMessage = ex.getMessage();
        }
      } catch (Exception ex) {
        errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CONN_FAILED_MSG);
      } finally {
        if (parent.progressForm != null) {
          // end the background thread of progress gauge.
          Gauge progressGauge = (Gauge) parent.progressForm.get(parent.progressGaugeIndex);
          progressGauge.setValue(Gauge.CONTINUOUS_IDLE);
        }

        try {
          conn.close();
          in.close();
        } catch (Exception e) {
          if (Logging.REPORT_LEVEL <= Logging.WARNING) {
            Logging.report(Logging.WARNING, LogChannels.LC_AMS, "close threw an Exception");
          }
        }
      }

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.ERROR), errorMessage, null, AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      parent.display.setCurrent(a, parent.urlTextBox);
    }
Esempio n. 23
0
  public InputStream makeRequest(String url, OutputStream pos) throws IOException {
    HttpConnection conn = null;
    ByteArrayOutputStream bos = null;
    DataInputStream is = null;
    DataOutputStream os = null;
    InputStream pis = null;

    try {
      conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
      conn.setRequestMethod(HttpConnection.POST);
      conn.setRequestProperty("Content-Type", "application/octet-stream");
      conn.setRequestProperty("Accept", "application/octet-stream");

      if (sessionCookie == null) {
        conn.setRequestProperty("version", "???");
      } else {
        conn.setRequestProperty("cookie", sessionCookie);
      }

      // Getting the output stream may flush the headers
      os = conn.openDataOutputStream();
      os.write(pos.getBytes());
      os.close();

      int responseCode;
      try {
        responseCode = conn.getResponseCode();
      } catch (IOException e) {
        throw new IOException("No response from " + url);
      }

      if (responseCode != HttpConnection.HTTP_OK) {
        throw new IllegalArgumentException();
      }

      bos = new ByteArrayOutputStream();
      {
        is = conn.openDataInputStream();
        String sc = conn.getHeaderField("set-cookie");
        if (sc != null) {
          sessionCookie = sc;
        }

        while (true) {
          int ch = is.read();
          if (ch == -1) break;

          bos.write(ch);
        }

        is.close();
        is = null;

        conn.close();
        conn = null;
      }
      pis = new InputStream(bos.toByteArray());

      bos.close();
      bos = null;
    } catch (Exception e) {
      e.printStackTrace();
      try {
        if (conn != null) {
          conn.close();
          conn = null;
        }

        if (bos != null) {
          bos.close();
          bos = null;
        }

        if (is != null) {
          is.close();
          is = null;
        }
      } catch (Exception exc) {
      }
      throw new IOException();
    }

    return pis;
  }