forked from resteasy/resteasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipartRelatedInputImpl.java
81 lines (68 loc) · 2.41 KB
/
MultipartRelatedInputImpl.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
package org.jboss.resteasy.plugins.providers.multipart;
import org.apache.james.mime4j.dom.Multipart;
import org.apache.james.mime4j.dom.field.ContentTypeField;
import org.apache.james.mime4j.dom.field.FieldName;
import org.apache.james.mime4j.message.BodyPart;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.Providers;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Implements {@link MultipartRelatedInput} by extending
* {@link MultipartInputImpl} and adding multipart/related functionality.
*
* @author Attila Kiraly
* @version $Revision: 1 $
*/
public class MultipartRelatedInputImpl extends MultipartInputImpl implements
MultipartRelatedInput {
private Map<String, InputPart> relatedMap;
private String start;
private String startInfo;
private String type;
private InputPart rootPart;
public MultipartRelatedInputImpl(final MediaType contentType, final Providers workers) {
super(contentType, workers);
}
public MultipartRelatedInputImpl (final Multipart multipart, final Providers workers)
throws IOException {
super(multipart, workers);
}
@Override
public void parse(InputStream is) throws IOException {
super.parse(is);
ContentTypeField contentTypeField = (ContentTypeField) getMimeMessage()
.getHeader().getField(FieldName.CONTENT_TYPE);
start = contentTypeField.getParameter("start");
startInfo = contentTypeField.getParameter("start-info");
type = contentTypeField.getParameter("type");
rootPart = start == null ? getParts().get(0) : getRelatedMap().get(start);
}
@Override
protected InputPart extractPart(BodyPart bodyPart) throws IOException {
InputPart inputPart = super.extractPart(bodyPart);
getRelatedMap()
.put(inputPart.getHeaders().getFirst("Content-ID"), inputPart);
return inputPart;
}
public Map<String, InputPart> getRelatedMap() {
if (relatedMap == null) {
relatedMap = new LinkedHashMap<String, InputPart>();
}
return relatedMap;
}
public InputPart getRootPart() {
return rootPart;
}
public String getStart() {
return start;
}
public String getStartInfo() {
return startInfo;
}
public String getType() {
return type;
}
}