View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.opennap.net;
21  
22  import java.io.File;
23  import java.io.Serializable;
24  
25  /***
26   * 
27   */
28  public class OpenNapSegmentData implements Serializable {
29  
30  	//--- Constant(s) ---
31  
32  	//--- Data Field(s) ---
33  
34  	/***
35  	 * The offset in the final file.
36  	 */
37  	long start;
38  
39  	/***
40  	 * The file that the segment is saved to.
41  	 */
42  	File file;
43  
44  	/***
45  	 * The number of times a merge with this segment has failed.
46  	 */
47  	int mergeFailCount;
48  
49      //--- Constructor(s) ---
50  
51      public OpenNapSegmentData()
52      {
53  	}
54  
55      //--- Methods ---
56  
57  	public void setFile(File parent, String filename)
58  	{
59  		if (filename == null || filename.length() == 0) {
60  			throw new IllegalArgumentException();
61  		}
62  
63  		File file = new File(filename);
64  		if (!file.exists()) {
65  			// check if the incomplete folder was moved
66  			file = new File(parent, file.getName());
67  			if (!file.exists()) {
68  				throw new IllegalArgumentException();
69  			}
70  		}
71  
72  		this.file = file;
73  	}
74  
75  	public void setMergeFailCount(String mergeFailCount)
76  	{
77  		if (mergeFailCount == null) {
78  			throw new IllegalArgumentException();
79  		}
80  
81  		try {
82  			this.mergeFailCount = Integer.parseInt(mergeFailCount);
83  		}
84  		catch (NumberFormatException e) {
85  			throw new IllegalArgumentException();
86  		}
87  	}
88  
89  	public void setStart(String start)
90  	{
91  		if (start == null) {
92  			throw new IllegalArgumentException();
93  		}
94  
95  		try {
96  			this.start = Long.parseLong(start);
97  		}
98  		catch (NumberFormatException e) {
99  			throw new IllegalArgumentException();
100 		}
101 	}
102 
103 }
104 
105 
106 
107