1 | package fr.sii.ogham.core.resource; | |
2 | ||
3 | import java.io.File; | |
4 | import java.io.FileInputStream; | |
5 | import java.io.IOException; | |
6 | import java.io.InputStream; | |
7 | ||
8 | import fr.sii.ogham.core.util.EqualsBuilder; | |
9 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
10 | ||
11 | /** | |
12 | * Resource that provide access to a file. | |
13 | * | |
14 | * @author Aurélien Baudet | |
15 | * | |
16 | */ | |
17 | public class FileResource implements NamedResource { | |
18 | /** | |
19 | * The file to attach | |
20 | */ | |
21 | private File file; | |
22 | ||
23 | /** | |
24 | * The name for the attachment | |
25 | */ | |
26 | private String name; | |
27 | ||
28 | /** | |
29 | * Initialize the resource with the provided file and name. The file is the | |
30 | * content of the resource. Use the provided name for the resource name | |
31 | * instead of the name of the file. | |
32 | * | |
33 | * @param file | |
34 | * the content of the resource | |
35 | * @param name | |
36 | * the name for the resource | |
37 | */ | |
38 | public FileResource(File file, String name) { | |
39 | super(); | |
40 | this.file = file; | |
41 | this.name = name; | |
42 | } | |
43 | ||
44 | /** | |
45 | * Initialize the resource with the provided file. The file is the content | |
46 | * of the resource. Use the name of the file for the name of the resource. | |
47 | * | |
48 | * @param file | |
49 | * the content of the resource | |
50 | */ | |
51 | public FileResource(File file) { | |
52 | this(file, file.getName()); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Initialize the resource with the provided file. The file is the content | |
57 | * of the resource. Use the name of the file for the name of the resource. | |
58 | * | |
59 | * @param fileName | |
60 | * the content of the resource | |
61 | */ | |
62 | public FileResource(String fileName) { | |
63 | this(new File(fileName)); | |
64 | } | |
65 | ||
66 | @Override | |
67 | public InputStream getInputStream() throws IOException { | |
68 |
2
1. getInputStream : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getInputStream → NO_COVERAGE 2. getInputStream : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getInputStream → KILLED |
return new FileInputStream(file); |
69 | } | |
70 | ||
71 | public File getFile() { | |
72 |
4
1. getFile : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getFile → NO_COVERAGE 2. getFile : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getFile → KILLED 3. getFile : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getFile → KILLED 4. getFile : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getFile → KILLED |
return file; |
73 | } | |
74 | ||
75 | public String getName() { | |
76 |
4
1. getName : replaced return value with "" for fr/sii/ogham/core/resource/FileResource::getName → NO_COVERAGE 2. getName : replaced return value with "" for fr/sii/ogham/core/resource/FileResource::getName → KILLED 3. getName : replaced return value with "" for fr/sii/ogham/core/resource/FileResource::getName → KILLED 4. getName : replaced return value with "" for fr/sii/ogham/core/resource/FileResource::getName → KILLED |
return name; |
77 | } | |
78 | ||
79 | @Override | |
80 | public int hashCode() { | |
81 |
3
1. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/FileResource::hashCode → NO_COVERAGE 2. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/FileResource::hashCode → SURVIVED 3. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/FileResource::hashCode → KILLED |
return new HashCodeBuilder().append(name, file).hashCode(); |
82 | } | |
83 | ||
84 | @Override | |
85 | public boolean equals(Object obj) { | |
86 |
4
1. equals : replaced boolean return with false for fr/sii/ogham/core/resource/FileResource::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/core/resource/FileResource::equals → NO_COVERAGE 3. equals : replaced boolean return with false for fr/sii/ogham/core/resource/FileResource::equals → KILLED 4. equals : replaced boolean return with true for fr/sii/ogham/core/resource/FileResource::equals → KILLED |
return new EqualsBuilder(this, obj).appendFields("name", "file").isEqual(); |
87 | } | |
88 | } | |
Mutations | ||
68 |
1.1 2.2 |
|
72 |
1.1 2.2 3.3 4.4 |
|
76 |
1.1 2.2 3.3 4.4 |
|
81 |
1.1 2.2 3.3 |
|
86 |
1.1 2.2 3.3 4.4 |