1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.http2;
17
18 import java.nio.charset.Charset;
19
20
21
22
23
24
25
26
27
28
29
30
31 public class MemoryFileUpload extends AbstractMemoryHttpData implements FileUpload {
32
33 private String filename = null;
34
35 private String contentType = null;
36
37 private String contentTransferEncoding = null;
38
39 public MemoryFileUpload(String name, String filename, String contentType,
40 String contentTransferEncoding, Charset charset, long size)
41 throws NullPointerException, IllegalArgumentException {
42 super(name, charset, size);
43 setFilename(filename);
44 setContentType(contentType);
45 setContentTransferEncoding(contentTransferEncoding);
46 }
47
48 public HttpDataType getHttpDataType() {
49 return HttpDataType.FileUpload;
50 }
51
52 public String getFilename() {
53 return filename;
54 }
55
56 public void setFilename(String filename) {
57 if (filename == null) {
58 throw new NullPointerException("filename");
59 }
60 this.filename = filename;
61 }
62
63 @Override
64 public int hashCode() {
65 return getName().hashCode();
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (!(o instanceof Attribute)) {
71 return false;
72 }
73 Attribute attribute = (Attribute) o;
74 return getName().equalsIgnoreCase(attribute.getName());
75 }
76
77 public int compareTo(InterfaceHttpData arg0) {
78 if (!(arg0 instanceof FileUpload)) {
79 throw new ClassCastException("Cannot compare " + getHttpDataType() +
80 " with " + arg0.getHttpDataType());
81 }
82 return compareTo((FileUpload) arg0);
83 }
84
85 public int compareTo(FileUpload o) {
86 int v;
87 v = getName().compareToIgnoreCase(o.getName());
88 if (v != 0) {
89 return v;
90 }
91
92 return v;
93 }
94
95 public void setContentType(String contentType) {
96 if (contentType == null) {
97 throw new NullPointerException("contentType");
98 }
99 this.contentType = contentType;
100 }
101
102 public String getContentType() {
103 return contentType;
104 }
105
106 public String getContentTransferEncoding() {
107 return contentTransferEncoding;
108 }
109
110 public void setContentTransferEncoding(String contentTransferEncoding) {
111 this.contentTransferEncoding = contentTransferEncoding;
112 }
113
114 @Override
115 public String toString() {
116 return HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
117 HttpPostBodyUtil.FORM_DATA+"; "+HttpPostBodyUtil.NAME+"=\"" + getName() +
118 "\"; "+HttpPostBodyUtil.FILENAME+"=\"" + filename + "\"\r\n" +
119 HttpHeaders.Names.CONTENT_TYPE+": " + contentType +
120 (charset != null? "; "+HttpHeaders.Values.CHARSET+"=" + charset + "\r\n" : "\r\n") +
121 HttpHeaders.Names.CONTENT_LENGTH+": " + length() + "\r\n" +
122 "Completed: " + isCompleted() +
123 "\r\nIsInMemory: " + isInMemory();
124 }
125 }