-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageReader.java
44 lines (35 loc) · 1.02 KB
/
ImageReader.java
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
package qiwi.util.image;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
public class ImageReader {
private static final transient Logger log = LoggerFactory.getLogger(ImageReader.class);
private final byte[] image;
protected ImageReader(String fileName) {
this.image = readImage(fileName);
}
@NotNull
private byte[] readImage(@NotNull String name) {
try {
final byte[] image = IOUtils.toByteArray(readStream(name));
if (log.isDebugEnabled()) {
log.debug("Read the file by name " + name + " has a size " + image.length);
}
return image;
} catch (IOException e) {
log.error("DefaultImageReader exception", e);
throw new IllegalStateException(e);
}
}
@NotNull
private InputStream readStream(@NotNull String name) {
return this.getClass().getResourceAsStream(String.format("img/%s", name));
}
@NotNull
public byte[] getImage() {
return image;
}
}