1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.transfer;
21
22 public class DefaultSegment implements Segment {
23
24 private int availability;
25 private long start;
26 private long end;
27 private long transferred;
28 private long total;
29
30
31 /***
32 *
33 * @param start the start offset of the segment in byte
34 * @param end the end offset of the segment in byte
35 * @param transferred the number of bytes transferred
36 */
37 public DefaultSegment(long total, long start, long end, long transferred,
38 int availability)
39 {
40 this.total = total;
41 this.start = start;
42 this.end = end;
43 this.transferred = transferred;
44 this.availability = availability;
45 }
46
47 /***
48 *
49 * @param start the start offset of the segment in byte
50 * @param end the end offset of the segment in byte
51 * @param transferred the number of bytes transferred
52 */
53 public DefaultSegment(long start, long end, long transferred,
54 int availability)
55 {
56 this(0, start, end, transferred, availability);
57 }
58
59 public DefaultSegment(long total)
60 {
61 this(total, 0, 0, 0, 0);
62 }
63
64 public void commit(int transferred)
65 {
66 if (start + this.transferred + transferred > end) {
67 this.transferred = end - start;
68 }
69 else {
70 this.transferred += transferred;
71 }
72 }
73
74 public int getAvailability()
75 {
76 return availability;
77 }
78
79 /***
80 * @return the end
81 */
82 public long getEnd()
83 {
84 return end;
85 }
86
87 /***
88 * @return the start
89 */
90 public long getStart()
91 {
92 return start;
93 }
94
95 /***
96 * @return the total byte
97 */
98 public long getTotal()
99 {
100 return total;
101 }
102
103 /***
104 * @return transferred bytes
105 */
106 public long getTransferred()
107 {
108 return transferred;
109 }
110
111 public void setAvailability(int avail)
112 {
113 availability = avail;
114 }
115
116 /***
117 * @param l
118 */
119 public void setEnd(long l)
120 {
121 end = l;
122 }
123
124 /***
125 * @param l
126 */
127 public void setStart(long l)
128 {
129 start = l;
130 }
131
132 public void setTotal(long l)
133 {
134 total = l;
135 }
136
137 /***
138 * @param l
139 */
140 public void setTransferred(long l)
141 {
142 transferred = l;
143 }
144
145 }