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 |
|
package info.magnolia.module.blossom.multipart; |
35 |
|
|
36 |
|
import java.io.File; |
37 |
|
import java.io.IOException; |
38 |
|
import java.io.InputStream; |
39 |
|
import java.io.Serializable; |
40 |
|
|
41 |
|
import org.apache.commons.io.FileUtils; |
42 |
|
import org.apache.commons.io.IOUtils; |
43 |
|
import org.springframework.web.multipart.MultipartFile; |
44 |
|
|
45 |
|
import info.magnolia.cms.beans.runtime.Document; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@see |
51 |
|
@see |
52 |
|
@since |
53 |
|
|
|
|
| 25% |
Uncovered Elements: 6 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
54 |
|
public class BlossomMultipartFile implements MultipartFile, Serializable { |
55 |
|
|
56 |
|
private Document document; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
1 |
public BlossomMultipartFile(Document document) {... |
59 |
1 |
this.document = document; |
60 |
|
} |
61 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
62 |
|
@Override... |
63 |
|
public byte[] getBytes() throws IOException { |
64 |
|
return IOUtils.toByteArray(document.getStream()); |
65 |
|
} |
66 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
67 |
|
@Override... |
68 |
|
public String getContentType() { |
69 |
|
return document.getType(); |
70 |
|
} |
71 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
72 |
|
@Override... |
73 |
|
public InputStream getInputStream() throws IOException { |
74 |
|
return document.getStream(); |
75 |
|
} |
76 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
77 |
|
@Override... |
78 |
|
public String getName() { |
79 |
|
return document.getAtomName(); |
80 |
|
} |
81 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
82 |
|
@Override... |
83 |
|
public String getOriginalFilename() { |
84 |
|
return document.getFileNameWithExtension(); |
85 |
|
} |
86 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
87 |
|
@Override... |
88 |
|
public long getSize() { |
89 |
|
return document.getLength(); |
90 |
|
} |
91 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
92 |
|
@Override... |
93 |
|
public boolean isEmpty() { |
94 |
|
return document.getLength() <= 0; |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
97 |
0 |
@Override... |
98 |
|
public void transferTo(File destination) throws IOException, IllegalStateException { |
99 |
|
|
100 |
|
|
101 |
0 |
if (destination.exists() && !destination.delete()) { |
102 |
0 |
throw new IOException("Destination file [" + destination.getAbsolutePath() + "] already exists and could not be deleted"); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
0 |
FileUtils.copyFile(document.getFile(), destination); |
107 |
|
} |
108 |
|
} |