1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
31
32
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
50
51 public OpenNapSegmentData()
52 {
53 }
54
55
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
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