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