⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskinfo.java

📁 一个基于NetBeans平台开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		this.taskDownloadSpeed = "0";
		this.taskUploadSpeed = "0";
		this.taskUsedTime = "0";
		this.taskRequireTime = "0";
	}

        //对现在结束任务步骤的更新,包括存盘和刷新任务显示。
	public void taskUpdata(){
		if ( this.taskInfoToDisk() ) System.out.println("成功将task数据写入磁盘,更新成功!");
                
                //把新数据显示在taskTable上
                taskTable.setValueAt(this.taskFinishedLength, this.taskIndex, 3);
                taskTable.setValueAt(this.taskPercentage, this.taskIndex, 4);
                taskTable.setValueAt(this.taskUploadSpeed, this.taskIndex, 5);
//                taskTable.setValueAt(this.taskUsedTime, this.taskIndex, 6);
//                taskTable.setValueAt(this.taskRequireTime, this.taskIndex, 7);
                
                taskTable.setValueAt(this.taskGroupName, this.taskIndex, 0);
                taskTable.setValueAt(this.taskFileName, this.taskIndex, 1);
                taskTable.setValueAt(this.taskFileLength, this.taskIndex, 2);
	}
	
	//用于join任务,根据刚刚下载的元文件,确定保存目录,以便保存以后得到的响应数据。
	private boolean createDir() throws IOException{
		File file = null;
		File root = null;
		int size = 0;
		
		//不是单文件
		if ( !this.getTaskRiverFileType().equals("single") ){
			BufferedRandomAccessFile braf = null;
			int a = ((Integer)this.getTaskDictionary().get("path_index")).intValue();
			String path = this.getTaskFileName();
//			String name = (String)this.getTaskDictionary().get("name");
			String p = null;
			root = new File(path);
			file = new File(path);
			root.mkdir();
			
			for(int i=1;i<=a;i++){
                            String s = (String)this.getTaskDictionary().get("path" + i);

                            StringTokenizer st = new StringTokenizer(s,"/");


                            while (st.hasMoreElements()){
                                    p = (String)st.nextElement();

                                    if ( !st.hasMoreElements()) break;

                                    file = new File(file,p);
                                    file.mkdir();
                            }

                            p += ".rs";
                            file = new File(file,p);
                            braf = new BufferedRandomAccessFile(file,"rw");

                            size = ((Integer)this.getTaskDictionary().get("length" + i)).intValue();

                            braf.setLength(size);
                            file = new File(path);
                            braf.close();
                      }
		}
		//是单文件
		else {
			BufferedRandomAccessFile braf = null;
			String path = this.getTaskFileName();
		
                	file = new File(path + ".rs");
                	braf = new BufferedRandomAccessFile(file,"rw");
	    	
                        size = ((Integer)this.getTaskDictionary().get("length")).intValue();
			
			braf.setLength(size);
			braf.close();
		}
		return true;
	}
	//根据单、多文件打开保存对话框
	private boolean saveFile(){
		if ( ((String)dictionary.get("type")).equals("single") ){
			File inFileName = null;
			
	 		JFileChooser jfc = new JFileChooser();
	 		jfc.setDialogTitle("选择要保存的目录。");
	 		jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	 		com.sinpool.rivercrescent.myutil.RSConfigure rsc = com.sinpool.rivercrescent.myutil.RSConfigure.readFromDisk();
                        File f = new File( rsc.getDefaultSavePath() );
                        jfc.setCurrentDirectory(f);
                        
                        int state = 0 ;
			
			state = jfc.showDialog(null,"Select");
			inFileName = jfc.getSelectedFile();
			
			if ( state != JFileChooser.APPROVE_OPTION ) return false;
			this.setTaskFileName(inFileName.getPath() + "\\" + (String)dictionary.get("name"));
	 	}
	 	else{
	 		JFileChooser jfc = new JFileChooser();
			jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			jfc.setDialogTitle("选择要保存的目录。");
	 		com.sinpool.rivercrescent.myutil.RSConfigure rsc = com.sinpool.rivercrescent.myutil.RSConfigure.readFromDisk();
                        File f = new File( rsc.getDefaultSavePath() );
                        jfc.setCurrentDirectory(f);
                        
			File inFileName = null;
			//选择要发布的文件夹
			int state = 0 ;
			
			state = jfc.showDialog(null,"Select");
			inFileName = jfc.getSelectedFile();
				
			if ( state != JFileChooser.APPROVE_OPTION ) return false;
			this.setTaskFileName(inFileName.getPath() + "\\" + (String)dictionary.get("name"));
	 	}
	 	
	 	return true;
	}
        
	int fileIndex = 0,fileDataIndex;		//多文件时使用的值,前者是指定块所在文件,后者是指定块在该文件的索引
	private void setSearchFilePer(String p){
		int pi = Integer.valueOf(p).intValue() - 1;
		for (int i=0;i<filePieceQueue.size();i++){
			if ( pi < ((Integer)filePieceQueue.get(i)).intValue() ){
				fileIndex = i+1;			//因为path的第一个值是"path1"
				
				//不是第一个文件时,
				if (i !=0) fileDataIndex = pi - ((Integer)filePieceQueue.get(i-1)).intValue();
				//是第一个文件时。
				else fileDataIndex = pi;
				return;
			}
		}
	}
	
	//以下是JavaBean方法。
	
	//获得当前任务所在的组(PeerGroup对象)
	public PeerGroup getTaskPeerGroup(){
		return this.currentGroup;
	}
	//获得此River文件的类型(single or multiple)
	public String getTaskRiverFileType(){
		return this.taskRiverFileType;
	}
	//夺得多文件时,指定块所在的文件(绝对文件名)
	//是publishUpload和JoinedUpload使用的。
	//因为单文件情况,在PublishUploadManager和JoinedUploadManager里已经处理了,
	//这里只是多文件的操作。
	public String getFileNameOfMultipleFromPiece(String p){
		this.setSearchFilePer(p);
		String temp = (String)dictionary.get("path"+ fileIndex );
		return this.getTaskFileName() + "/" + temp;
	}
	//获得多文件时,指定块所在文件的数据索引,不用指定块数。
	//但是,必须在调用getFileNameOfMultipleFromPiece(String p)方法后,再调用此方法。
	public String getFileDataIndex(){
System.out.println("fileIndex: " + fileIndex);
		return String.valueOf(fileDataIndex);
	}
	//获得字典
	public Hashtable getTaskDictionary(){
		return this.dictionary;
	}
	//获得组名
	public String getTaskRiverscentFileName(){
		return "riverfile\\" + this.taskRiverscentFileName;
	}
	//获得组ID
	public String getTaskGroupID(){
                return this.taskGroupID;
	}
	//获得组名
	public String getTaskGroupName(){
		return this.taskGroupName;
	}
	/*获得文件名,
	 *单文件时,绝对路径文件名
	 *多文件时,绝对路径名
	 *是单文件、还是多文件,
	 *取决于构造函数时,传递的FileAbsolutePath参数
	 *构造函数时,这个参数通过EncoderBencoding对象获得
         *以上是publish任务;
         *包括name ,join任务时由saveFile方法设置。
	 */
	
	public String getTaskFileName(){
		return this.taskFileName;
	}
	//获得文件大小
	public String getTaskFileLength(){
		return this.taskFileLength;
	}
	//获得完成数
	public String getTaskFinishedLength(){
		return this.taskFinishedLength;
	}
	//获得百分比
	public String getTaskPercentage(){
		return this.taskPercentage;
	}
	//获得上传速度
	public String getTaskUploadSpeed(){
		return this.taskUploadSpeed;
	}
	//获得下载速度
	public String getTaskDownloadSpeed(){
		return this.taskDownloadSpeed;
	}
	//获得用时
	public String getTaskUsedTime(){
		return this.taskUsedTime;
	}
	//获得需时
	public String getTaskRequireTime(){
		return this.taskRequireTime;
	}
	//获得管道服务
	public PipeService getTaskPipes(){
		return this.taskPipes;
	}
	//获得管道通告
	public PipeAdvertisement getTaskPipeadv(){
		return this.taskPipeadv;
	}
	//获得任务类型(join or publish)
	public String getTaskType(){
		return this.taskType;
	}
	//获得任务块长度。
	public String getTaskPieceLength(){
		return this.taskPieceLength;
	}
	//获得此任务已完成的索引数组
	public boolean[] getTaskFinishedPieces(){
		return this.finishedPieces;
	}
	//获得此任务在加入任务组的索引号
        public int getTaskIndex(){
            return this.taskIndex;
        }

	//获得此任务在加入任务组的索引号
        public String getTaskPipeID(){
            return this.taskPipeID;
        }
        public DefaultTableModel getTaskStatusTableModel(){
            return this.taskStatusTableModel;
        }
        /////////////////////////////////////////////
	//设置此任务在加入任务组的索引号
        public void setTaskIndex(int i){
            this.taskIndex = i;
        }
	//设置组名
	public void setTaskGroupName(String value){
		this.taskGroupName = value;
	}
	//设置文件名
	public void setTaskFileName(String value){
		this.taskFileName = value;
		System.out.println("taskFileName: " + this.taskFileName);
	}
	//设置文件大小
	public void setTaskFileLength(String value){
		this.taskFileLength = value;
	}
	//设置完成数
	public void setTaskFinishedLength(String value){
		this.taskFinishedLength = value;
	}
	//设置百分比
	public void setTaskPercentage(String value){
		this.taskPercentage = value;
		System.out.println("taskPercentage" + this.taskPercentage);
	}
	//设置上传速度
	public void setTaskUploadSpeed(String value){
		this.taskUploadSpeed = value;
		System.out.println("taskUploadSpeed" + this.taskUploadSpeed);
	}
	//设置下载速度
	public void setTaskDownloadSpeed(String value){
		this.taskDownloadSpeed = value;
		System.out.println("taskDownloadSpeed" + this.taskDownloadSpeed);
	}
	//设置用时
	public void setTaskUsedTime(String value){
		this.taskUsedTime = value;
		System.out.println("taskUsedTime" + this.taskUsedTime);
	}
	//设置需时
	public void setTaskRequireTime(String value){
		this.taskRequireTime = value;
		System.out.println("taskRequireTime" + this.taskRequireTime);
	}
	//设置完成的文件块
	public void setTaskFinishedPieceIndex(String block){
		int i = Integer.valueOf(block).intValue();
		this.finishedPieces[i] = true;
	}
	//设置管道服务
	public void setTaskPipes(PipeService ps){
		this.taskPipes = ps;
	}
	//设置管道通告
	public void setTaskPipeadv(PipeAdvertisement pad){
		this.taskPipeadv = pad;
	}
        //设置JTable
        public void setTaskTable(JTable jt){
            this.taskTable = jt;
        }
        //设置写任务状态的JTable
        public void setTaskStatusTableModel(DefaultTableModel dtm){
            this.taskStatusTableModel = dtm;
        }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -