1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.store.legacy.doc.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.FileInputStream; |
24 |
|
import java.io.IOException; |
25 |
|
import java.io.InputStream; |
26 |
|
|
27 |
|
import org.apache.commons.io.IOUtils; |
28 |
|
import org.apache.commons.io.input.AutoCloseInputStream; |
29 |
|
import org.xwiki.store.UnexpectedException; |
30 |
|
|
31 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
32 |
|
import com.xpn.xwiki.doc.XWikiAttachmentContent; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 35.1% |
Uncovered Elements: 24 (37) |
Complexity: 12 |
Complexity Density: 0.52 |
|
41 |
|
public class FilesystemAttachmentContent extends XWikiAttachmentContent |
42 |
|
{ |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
private final File storageFile; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
@param |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
54 |
9 |
public FilesystemAttachmentContent(final File storage, final XWikiAttachment attachment)... |
55 |
|
{ |
56 |
9 |
super(attachment, null); |
57 |
9 |
this.storageFile = storage; |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
@since |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
67 |
1 |
public FilesystemAttachmentContent(final File storage)... |
68 |
|
{ |
69 |
1 |
super(null, null); |
70 |
1 |
this.storageFile = storage; |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
3 |
@Override... |
74 |
|
public FilesystemAttachmentContent clone() |
75 |
|
{ |
76 |
3 |
return new FilesystemAttachmentContent(this.storageFile, this.getAttachment()); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
79 |
0 |
@Override... |
80 |
|
@Deprecated |
81 |
|
public byte[] getContent() |
82 |
|
{ |
83 |
0 |
if (this.getFileItem() != null) { |
84 |
0 |
return super.getContent(); |
85 |
|
} |
86 |
|
|
87 |
0 |
final InputStream is = this.getContentInputStream(); |
88 |
0 |
try { |
89 |
0 |
return IOUtils.toByteArray(is); |
90 |
|
} catch (IOException e) { |
91 |
0 |
throw new RuntimeException("Failed to load attachment content", e); |
92 |
|
} finally { |
93 |
0 |
IOUtils.closeQuietly(is); |
94 |
|
} |
95 |
|
} |
96 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
97 |
4 |
@Override... |
98 |
|
public InputStream getContentInputStream() |
99 |
|
{ |
100 |
4 |
if (this.getFileItem() != null) { |
101 |
0 |
return super.getContentInputStream(); |
102 |
|
} |
103 |
|
|
104 |
4 |
try { |
105 |
4 |
return new AutoCloseInputStream(new FileInputStream(this.storageFile)); |
106 |
|
} catch (IOException e) { |
107 |
0 |
throw new UnexpectedException("Failed to get InputStream", e); |
108 |
|
} |
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
111 |
0 |
@Override... |
112 |
|
public int getSize() |
113 |
|
{ |
114 |
0 |
if (this.getFileItem() != null) { |
115 |
0 |
return super.getSize(); |
116 |
|
} |
117 |
|
|
118 |
0 |
long size = this.storageFile.length(); |
119 |
|
|
120 |
0 |
if (size > ((long) Integer.MAX_VALUE)) { |
121 |
0 |
return Integer.MAX_VALUE; |
122 |
|
} |
123 |
0 |
return (int) size; |
124 |
|
} |
125 |
|
} |