1package eu.siacs.conversations.entities;
2
3import java.io.File;
4
5import eu.siacs.conversations.utils.MimeUtils;
6
7public class DownloadableFile extends File {
8
9 private static final long serialVersionUID = 2247012619505115863L;
10
11 private long expectedSize = 0;
12 private byte[] sha1sum;
13 private byte[] aeskey;
14 private byte[] iv;
15
16 public DownloadableFile(String path) {
17 super(path);
18 }
19
20 public long getSize() {
21 return super.length();
22 }
23
24 public long getExpectedSize() {
25 return this.expectedSize;
26 }
27
28 public String getMimeType() {
29 String path = this.getAbsolutePath();
30 int start = path.lastIndexOf('.') + 1;
31 if (start < path.length()) {
32 String mime = MimeUtils.guessMimeTypeFromExtension(path.substring(start));
33 return mime == null ? "" : mime;
34 } else {
35 return "";
36 }
37 }
38
39 public void setExpectedSize(long size) {
40 this.expectedSize = size;
41 }
42
43 public byte[] getSha1Sum() {
44 return this.sha1sum;
45 }
46
47 public void setSha1Sum(byte[] sum) {
48 this.sha1sum = sum;
49 }
50
51 public void setKeyAndIv(byte[] keyIvCombo) {
52 if (keyIvCombo.length == 48) {
53 this.aeskey = new byte[32];
54 this.iv = new byte[16];
55 System.arraycopy(keyIvCombo, 0, this.iv, 0, 16);
56 System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32);
57 } else if (keyIvCombo.length >= 32) {
58 this.aeskey = new byte[32];
59 System.arraycopy(keyIvCombo, 0, aeskey, 0, 32);
60 }
61 }
62
63 public void setKey(byte[] key) {
64 this.aeskey = key;
65 }
66
67 public void setIv(byte[] iv) {
68 this.iv = iv;
69 }
70
71 public byte[] getKey() {
72 return this.aeskey;
73 }
74
75 public byte[] getIv() {
76 return this.iv;
77 }
78}