Package getFilePkg

Source Code of getFilePkg.GetFile

package getFilePkg;

import getFilePkg.config.*;
import getFilePkg.net.*;
import getFilePkg.net.applicationprotocol.http.*;
//import getFilePkg.threading.*;

import java.util.ArrayList;
import java.io.IOException;
import java.lang.Thread;


/**
* Main class which provides all the functionalities to the UI layer.
*
* @author biplap
*
*/
public class GetFile {
  private String hostname;
  private String url;
  private int protocol;
  //private Configurer confObj;
 
  //private ArrayList<ThreadManager> threadManagerList;
 
  public GetFile(){
    //threadManagerList = new ArrayList<ThreadManager>();
  }
 
  public void parseURL(String requestString){
    int index=0;
    int beginIndex;
    int endIndex;
    while(requestString.charAt(index)==' ')
      index++;
    switch(requestString.charAt(index)){
    case 'h':{
      protocol = Protocol.HTTP;
      break;
      }
    case 'f':{
      protocol = Protocol.FTP;
      break;
    }
    case 'w':{
      protocol = Protocol.HTTP;
      break;
    }
    }
    while(requestString.charAt(index)!='/')
      index++;
    index+=2;
    beginIndex=index;
    while(requestString.charAt(index)!='/' || index>=requestString.length())
      index++;
    endIndex=index;
    this.hostname=requestString.substring(beginIndex, endIndex);
    beginIndex=endIndex+1;
    this.url=requestString.substring(beginIndex);
  }

  public void download(String requestString){
    parseURL(requestString);
    startDownload();
  }
 
  private long startDownload(){
    ApplicationProtocol protocolHandler;
    Thread newThread=null;//=new Thread();
    switch(protocol){
    case Protocol.HTTP : {
      protocolHandler=new HTTPHandler();
      //newThread = new GetFileStartDownload(protocolHandler,"http://"+hostname+"/"+url,"aa",0,100);
      //threadManagerList.add(new ThreadManager(protocolHandler,newThread));
      //(new GetFileConnect(protocolHandler,hostname)).run();
      //newThread.run();
      break;
    }
    }
    return newThread.getId();
  }

  private void readConfig(){
    hostname=Configurer.getIP(hostname);
  }
 
  /*public void stopThreadById(long threadId){
    for(int i=0;i<threadManagerList.size();i++){
      if(threadManagerList.get(i).getThread().getId()==threadId){
        threadManagerList.get(i).getThread().stop();
      }
    }
  }*/
 
  /**
   * Returns the file size of the remote file.
   * @param hostname
   * @param url
   * @return file size
   */
  public long getFileSize(String hostname,String url){
    HTTPHandler httpObj=new HTTPHandler();
    try {
      return httpObj.getFileSize(hostname, url);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    }
  }
}
TOP

Related Classes of getFilePkg.GetFile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.