Пример #1
0
    private boolean verifyFile(File aFile, List theFileAttribList) {
      Iterator it = theFileAttribList.iterator();
      int theIndex = 0;
      String theMD5 = null;
      String theVal = null;
      long theSize;
      while (it.hasNext()) {
        try {
          theVal = (String) it.next();
          if (theIndex == 6) {
            theMD5 = MD5.getMD5(aFile);
            if (!theVal.equals(MD5.getMD5(aFile))) {
              return false;
            }
            break;
          }
          if (theIndex == 5) {
            theSize = aFile.length();
            if (theSize != Long.parseLong(theVal)) {
              return false;
            }
          }

        } catch (Exception E) {
          E.printStackTrace();
        }
        theIndex++;
      }
      return true;
    }
Пример #2
0
    private void downloadFile(String theFilename) {
      OutputStream outStream = null;
      InputStream is = null;
      try {
        myMessage.stateChanged("DOWNLOADLOCALBASE");
        String theFile =
            myProperties
                .getProperty("BASEURL")
                .substring(0, myProperties.getProperty("BASEURL").lastIndexOf("/"));

        theFile = theFile + "/" + (new URI((theFilename).replaceAll(" ", "%20")));
        URLConnection uCon = null;
        int size = 1024;
        URL Url;
        byte[] buf;
        int ByteRead, ByteWritten = 0;
        Url = new URL(theFile);
        String theLocalFilename = (String) myFileList.get(theFilename).get(2);
        long theFileSize = Long.parseLong((String) myFileList.get(theFilename).get(5));
        outStream =
            new BufferedOutputStream(
                new FileOutputStream(
                    myProperties.getProperty("LOCALBASEDIR")
                        + "\\"
                        + myFileList.get(theFilename).get(2)));

        uCon = Url.openConnection();
        is = uCon.getInputStream();
        buf = new byte[size];
        while ((ByteRead = is.read(buf)) != -1) {
          outStream.write(buf, 0, ByteRead);
          ByteWritten += ByteRead;
          myMessage.setProgress((int) getPercentage(ByteWritten, theFileSize));
          // System.out.println(ByteWritten);
        }
        myMessage.messageChanged("Downloaded Successfully.");
        myMessage.messageChanged(
            "File name:\""
                + theLocalFilename
                + "\"\nNo ofbytes :"
                + ByteWritten
                + "Filesize ="
                + theFileSize);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          is.close();
          outStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
Пример #3
0
  /**
   * Searches for contact ids in history of recent messages.
   *
   * @param provider
   * @param after
   * @return
   */
  List<String> getRecentContactIDs(String provider, Date after) {
    List<String> res = new ArrayList<String>();

    try {
      History history = getHistory();

      if (history != null) {
        Iterator<HistoryRecord> recs = history.getReader().findLast(NUMBER_OF_MSGS_IN_HISTORY);
        SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT);

        while (recs.hasNext()) {
          HistoryRecord hr = recs.next();

          String contact = null;
          String recordProvider = null;
          Date timestamp = null;

          for (int i = 0; i < hr.getPropertyNames().length; i++) {
            String propName = hr.getPropertyNames()[i];

            if (propName.equals(STRUCTURE_NAMES[0])) recordProvider = hr.getPropertyValues()[i];
            else if (propName.equals(STRUCTURE_NAMES[1])) contact = hr.getPropertyValues()[i];
            else if (propName.equals(STRUCTURE_NAMES[2])) {
              try {
                timestamp = sdf.parse(hr.getPropertyValues()[i]);
              } catch (ParseException e) {
                timestamp = new Date(Long.parseLong(hr.getPropertyValues()[i]));
              }
            }
          }

          if (recordProvider == null || contact == null) continue;

          if (after != null && timestamp != null && timestamp.before(after)) continue;

          if (recordProvider.equals(provider)) res.add(contact);
        }
      }
    } catch (IOException ex) {
      logger.error("cannot create recent_messages history", ex);
    }

    return res;
  }
Пример #4
0
    private boolean getStatus(long theFileSize) {
      URL theURL = null;
      ;
      try {
        theURL = new URL(myProperties.getProperty("BASEURL"));
      } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      ;

      String data = "";
      boolean theStatus = false;
      try {
        data =
            URLEncoder.encode("filelocation", "UTF-8")
                + "="
                + URLEncoder.encode(myProperties.getProperty("REMOTEBASEDIR"), "UTF-8");
        data +=
            "&"
                + URLEncoder.encode("fileprocess", "UTF-8")
                + "="
                + URLEncoder.encode("STATUS", "UTF-8");
        data +=
            "&"
                + URLEncoder.encode("filename", "UTF-8")
                + "="
                + URLEncoder.encode(myProperties.getProperty("REMOTEDOWNLOADFILENAME"), "UTF-8");

        URLConnection conn = theURL.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line2;
        CSV theParser = new CSV('|');
        while (((line2 = rd.readLine()) != null) && !isCancelled()) {
          List list = theParser.parse(line2);
          System.out.println((String) list.get(0));
          if (((String) list.get(0)).equals(" Process running")) {
            theStatus = true;
            myMessage.messageChanged(
                (int) getPercentage(Long.parseLong((String) list.get(1)), theFileSize),
                "Process Running downloaded " + (String) list.get(1) + " bytes");
          }
          if (((String) list.get(0)).equals(" Process stopped")) {
            theStatus = false;
            myMessage.messageChanged(
                (int) getPercentage(Long.parseLong((String) list.get(1)), theFileSize),
                "Process Stopped File size =  " + (String) list.get(1) + " bytes");
          }
        }
        rd.close();

      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      System.out.println("theStatus =" + theStatus);
      return theStatus;
    }