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.io.File;
19 import java.nio.charset.Charset;
20
21
22
23
24
25
26
27
28
29
30 public class DiskFileUpload extends AbstractDiskHttpData implements FileUpload {
31 public static String baseDirectory = null;
32
33 public static boolean deleteOnExitTemporaryFile = true;
34
35 public static String prefix = "FUp_";
36
37 public static String postfix = ".tmp";
38
39 private String filename = null;
40
41 private String contentType = null;
42
43 private String contentTransferEncoding = null;
44
45 public DiskFileUpload(String name, String filename, String contentType,
46 String contentTransferEncoding, Charset charset, long size)
47 throws NullPointerException, IllegalArgumentException {
48 super(name, charset, size);
49 setFilename(filename);
50 setContentType(contentType);
51 setContentTransferEncoding(contentTransferEncoding);
52 }
53
54 public HttpDataType getHttpDataType() {
55 return HttpDataType.FileUpload;
56 }
57
58
59
60
61 public String getFilename() {
62 return filename;
63 }
64
65
66
67
68 public void setFilename(String filename) {
69 if (filename == null) {
70 throw new NullPointerException("filename");
71 }
72 this.filename = filename;
73 }
74
75 @Override
76 public int hashCode() {
77 return getName().hashCode();
78 }
79
80 @Override
81 public boolean equals(Object o) {
82 if (!(o instanceof Attribute)) {
83 return false;
84 }
85 Attribute attribute = (Attribute) o;
86 return getName().equalsIgnoreCase(attribute.getName());
87 }
88
89 public int compareTo(InterfaceHttpData arg0) {
90 if (!(arg0 instanceof FileUpload)) {
91 throw new ClassCastException("Cannot compare " + getHttpDataType() +
92 " with " + arg0.getHttpDataType());
93 }
94 return compareTo((FileUpload) arg0);
95 }
96
97 public int compareTo(FileUpload o) {
98 int v;
99 v = getName().compareToIgnoreCase(o.getName());
100 if (v != 0) {
101 return v;
102 }
103
104 return v;
105 }
106
107 public void setContentType(String contentType) {
108 if (contentType == null) {
109 throw new NullPointerException("contentType");
110 }
111 this.contentType = contentType;
112 }
113
114 public String getContentType() {
115 return contentType;
116 }
117
118 public String getContentTransferEncoding() {
119 return contentTransferEncoding;
120 }
121
122 public void setContentTransferEncoding(String contentTransferEncoding) {
123 this.contentTransferEncoding = contentTransferEncoding;
124 }
125
126 @Override
127 public String toString() {
128 return HttpPostBodyUtil.CONTENT_DISPOSITION+": "+
129 HttpPostBodyUtil.FORM_DATA+"; "+HttpPostBodyUtil.NAME+"=\"" + getName() +
130 "\"; "+HttpPostBodyUtil.FILENAME+"=\"" + filename + "\"\r\n" +
131 HttpHeaders.Names.CONTENT_TYPE+": " + contentType +
132 (charset != null? "; "+HttpHeaders.Values.CHARSET+"=" + charset + "\r\n" : "\r\n") +
133 HttpHeaders.Names.CONTENT_LENGTH+": " + length() + "\r\n" +
134 "Completed: " + isCompleted() +
135 "\r\nIsInMemory: " + isInMemory() + "\r\nRealFile: " +
136 file.getAbsolutePath() + " DefaultDeleteAfter: " +
137 deleteOnExitTemporaryFile;
138 }
139
140 @Override
141 protected boolean deleteOnExit() {
142 return deleteOnExitTemporaryFile;
143 }
144
145 @Override
146 protected String getBaseDirectory() {
147 return baseDirectory;
148 }
149
150 @Override
151 protected String getDiskFilename() {
152 File file = new File(filename);
153 return file.getName();
154 }
155
156 @Override
157 protected String getPostfix() {
158 return postfix;
159 }
160
161 @Override
162 protected String getPrefix() {
163 return prefix;
164 }
165 }