Exemplo n.º 1
0
    private void getFileList() {
      myMessage.stateChanged("REMOTEFILELIST");
      URL theURL = null;
      ;
      try {
        theURL = new URL(myProperties.getProperty("BASEURL"));
      } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      ;

      String theRemoteBaseDir = myProperties.getProperty("REMOTEBASEDIR");
      Properties props = System.getProperties();
      props.put("http.proxyHost", myProperties.getProperty("PROXYHOST"));
      props.put("http.proxyPort", myProperties.getProperty("PROXYPORT"));
      String data = "";
      try {
        data =
            URLEncoder.encode("filelocation", "UTF-8")
                + "="
                + URLEncoder.encode(theRemoteBaseDir, "UTF-8");
        data +=
            "&"
                + URLEncoder.encode("fileprocess", "UTF-8")
                + "="
                + URLEncoder.encode("REMOTEFILELIST", "UTF-8");

        URLConnection conn = theURL.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
        myMessage.messageChanged(0, "Get the File List");
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line2;
        myFileList = new HashMap<String, List>();
        while (((line2 = rd.readLine()) != null) && !isCancelled()) {
          CSV parser = new CSV('|');
          List theFileList = parser.parse(line2);
          // myFileList.put((String)theFileList.get(1), theFileList);
          for (int i = 0; i < theFileList.size(); i++) {
            if (i == 1) {
              myFileList.put((String) theFileList.get(i), theFileList);
            }
          }
        }
        rd.close();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
Exemplo n.º 2
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;
    }