forked from thombergs/docx-stamper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image.java
90 lines (72 loc) · 2.2 KB
/
Image.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package org.wickedsource.docxstamper.replace.typeresolver.image;
import org.apache.commons.io.IOUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* This class describes an image which will be inserted into document.
*/
public class Image {
private byte[] imageBytes;
private String filename;
private String altText;
private Integer maxWidth;
/**
* @param in - content of the image as InputStream
* @throws IOException if image cannot be read
*/
public Image(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
this.imageBytes = out.toByteArray();
}
/**
* @param in - content of the image as InputStream
* @param maxWidth - max width of the image in twip
* @throws IOException if image cannot be read
*/
public Image(InputStream in, Integer maxWidth) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
this.imageBytes = out.toByteArray();
this.maxWidth = maxWidth;
}
/**
* @param imageBytes - content of the image as array of the bytes
*/
public Image(byte[] imageBytes) {
this.imageBytes = imageBytes;
}
/**
* @param imageBytes - content of the image as array of the bytes
* @param maxWidth - max width of the image in twip
*/
public Image(byte[] imageBytes, Integer maxWidth) {
this.imageBytes = imageBytes;
this.maxWidth = maxWidth;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getAltText() {
return altText;
}
public void setAltText(String altText) {
this.altText = altText;
}
public byte[] getImageBytes() {
return imageBytes;
}
public void setImageBytes(byte[] imageBytes) {
this.imageBytes = imageBytes;
}
/**
* @return max width of the image in twip, if it is specified, or null.
*/
public Integer getMaxWidth() {
return maxWidth;
}
}