blob: 2c0cd6618bb3f8bda6a6cbe267084413346cc409 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package org.openslx.thrifthelper;
public class TransferStatusWrapper
{
public static enum BlockStatus {
COMPLETE, MISSING, UPLOADING, QUEUED_FOR_COPYING, COPYING, HASHING;
}
// 0 = complete, 1 = missing, 2 = uploading, 3 = queued for copying, 4 = copying, 5 = hashing (server side)
private byte[] blocks = null;
public TransferStatusWrapper(byte[] blocks) {
this.blocks = blocks;
}
public void setBlocks(byte[] blocks) {
this.blocks = blocks;
}
public boolean isComplete() {
for (byte block : blocks) {
if (block != 0)
return false;
}
return true;
}
public float getComplete() {
int done = 0;
for (byte block : blocks) {
if (block == 0 || block == 5) {
done++;
}
}
return ((float)done / (float)blocks.length);
}
public float getPercentComplete() {
return getComplete() * 100f;
}
public byte[] getBlocks() {
return this.blocks;
}
public boolean isEmpty() {
return blocks == null || blocks.length == 0;
}
public int getBlockCount() {
return blocks.length;
}
public BlockStatus get(int index) {
switch (blocks[index]) {
case 0:
return BlockStatus.COMPLETE;
case 1:
return BlockStatus.MISSING;
case 2:
return BlockStatus.UPLOADING;
case 3:
return BlockStatus.QUEUED_FOR_COPYING;
case 4:
return BlockStatus.COPYING;
}
return null;
}
}
|