1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.http.protocol;
22
23 import org.waarp.common.logging.WaarpLogger;
24 import org.waarp.common.logging.WaarpLoggerFactory;
25
26
27
28
29 public class HttpResumableInfo {
30 private static final WaarpLogger logger =
31 WaarpLoggerFactory.getLogger(HttpResumableInfo.class);
32
33 private int chunkNumber;
34 private int totalChunks;
35 private int chunkSize;
36 private long totalSize;
37 private String identifier;
38 private String filename;
39 private String relativePath;
40
41
42 public HttpResumableInfo(final int chunkNumber, final int chunkSize,
43 final long totalSize, final String identifier,
44 final String filename, final String relativePath) {
45 this.chunkNumber = chunkNumber;
46 this.chunkSize = chunkSize;
47 this.totalSize = totalSize;
48 this.identifier = identifier;
49 this.filename = filename;
50 this.relativePath = relativePath;
51 this.totalChunks =
52 (int) Math.ceil(((double) totalSize) / ((double) chunkSize));
53 logger.debug("{} {} {} {} {}", totalSize, chunkSize,
54 (totalSize) / chunkSize,
55 (int) Math.ceil(((double) totalSize) / ((double) chunkSize)),
56 totalChunks);
57 }
58
59
60
61
62
63 public final String getFilename() {
64 return filename;
65 }
66
67 public final HttpResumableInfo setFilename(final String filename) {
68 this.filename = filename;
69 return this;
70 }
71
72
73
74
75
76 public final String getRelativePath() {
77 return relativePath;
78 }
79
80 public final HttpResumableInfo setRelativePath(final String relativePath) {
81 this.relativePath = relativePath;
82 return this;
83 }
84
85
86
87
88
89
90
91
92 public final boolean isCompatible(final HttpResumableInfo resumableInfo) {
93 return resumableInfo.getChunkSize() == getChunkSize() &&
94 resumableInfo.getTotalSize() == getTotalSize() &&
95 resumableInfo.getIdentifier().equals(getIdentifier()) &&
96 resumableInfo.getTotalChunks() == getTotalChunks() &&
97 resumableInfo.getChunkNumber() <= getTotalChunks();
98 }
99
100
101
102
103
104
105
106 public final int getChunkSize() {
107 return chunkSize;
108 }
109
110 public final HttpResumableInfo setChunkSize(final int chunkSize) {
111 this.chunkSize = chunkSize;
112 return this;
113 }
114
115
116
117
118
119 public final long getTotalSize() {
120 return totalSize;
121 }
122
123 public final HttpResumableInfo setTotalSize(final long totalSize) {
124 this.totalSize = totalSize;
125 return this;
126 }
127
128
129
130
131 public final String getIdentifier() {
132 return identifier;
133 }
134
135
136
137
138 public final int getTotalChunks() {
139 return totalChunks;
140 }
141
142
143
144
145
146 public final int getChunkNumber() {
147 return chunkNumber;
148 }
149
150 public final HttpResumableInfo setChunkNumber(final int chunkNumber) {
151 this.chunkNumber = chunkNumber;
152 return this;
153 }
154
155 public final HttpResumableInfo setTotalChunks(final int totalChunks) {
156 this.totalChunks = totalChunks;
157 return this;
158 }
159
160 public final HttpResumableInfo setIdentifier(final String identifier) {
161 this.identifier = identifier;
162 return this;
163 }
164
165 @Override
166 public String toString() {
167 return "RI:{CN:" + chunkNumber + ", TC:" + totalChunks + ", CS:" +
168 chunkSize + ", TS:" + totalSize + ", ID:" + identifier + ", FN:" +
169 filename + ", RP:" + relativePath + "}";
170 }
171 }