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 java.nio.charset.Charset;
19
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.jboss.netty.util.CharsetUtil;
22
23
24
25
26 final class HttpPostBodyUtil {
27
28 public static int chunkSize = 8096;
29
30
31
32 public static final String CONTENT_DISPOSITION = "Content-Disposition";
33
34 public static final String NAME = "name";
35
36 public static final String FILENAME = "filename";
37
38
39
40
41 public static final String FORM_DATA = "form-data";
42
43
44
45
46 public static final String ATTACHMENT = "attachment";
47
48
49
50
51 public static final String FILE = "file";
52
53
54
55
56 public static final String MULTIPART_MIXED = "multipart/mixed";
57
58
59
60
61 public static final Charset ISO_8859_1 = CharsetUtil.ISO_8859_1;
62
63
64
65
66 public static final Charset US_ASCII = CharsetUtil.US_ASCII;
67
68
69
70
71 public static final String DEFAULT_BINARY_CONTENT_TYPE = "application/octet-stream";
72
73
74
75
76 public static final String DEFAULT_TEXT_CONTENT_TYPE = "text/plain";
77
78
79
80
81
82
83
84
85
86 public enum TransferEncodingMechanism {
87
88
89
90 BIT7("7bit"),
91
92
93
94 BIT8("8bit"),
95
96
97
98 BINARY("binary");
99
100 public String value;
101
102 TransferEncodingMechanism(String value) {
103 this.value = value;
104 }
105
106 TransferEncodingMechanism() {
107 value = name();
108 }
109
110 @Override
111 public String toString() {
112 return value;
113 }
114 }
115
116 private HttpPostBodyUtil() {
117 }
118
119
120
121
122
123 static class SeekAheadNoBackArrayException extends Exception {
124 private static final long serialVersionUID = -630418804938699495L;
125 }
126
127
128
129
130
131 static class SeekAheadOptimize {
132 byte[] bytes;
133
134 int readerIndex;
135
136 int pos;
137
138 int limit;
139
140 ChannelBuffer buffer;
141
142
143
144
145 SeekAheadOptimize(ChannelBuffer buffer) throws SeekAheadNoBackArrayException {
146 if (!buffer.hasArray()) {
147 throw new SeekAheadNoBackArrayException();
148 }
149 this.buffer = buffer;
150 bytes = buffer.array();
151 pos = readerIndex = buffer.arrayOffset() + buffer.readerIndex();
152 limit = buffer.arrayOffset() + buffer.writerIndex();
153 }
154
155
156
157
158
159
160 void setReadPosition(int minus) {
161 pos -= minus;
162 readerIndex = pos;
163 buffer.readerIndex(readerIndex);
164 }
165
166 void clear() {
167 buffer = null;
168 bytes = null;
169 limit = 0;
170 pos = 0;
171 readerIndex = 0;
172 }
173 }
174
175
176
177
178
179
180
181 static int findNonWhitespace(String sb, int offset) {
182 int result;
183 for (result = offset; result < sb.length(); result ++) {
184 if (!Character.isWhitespace(sb.charAt(result))) {
185 break;
186 }
187 }
188 return result;
189 }
190
191
192
193
194
195
196
197 static int findWhitespace(String sb, int offset) {
198 int result;
199 for (result = offset; result < sb.length(); result ++) {
200 if (Character.isWhitespace(sb.charAt(result))) {
201 break;
202 }
203 }
204 return result;
205 }
206
207
208
209
210
211
212 static int findEndOfString(String sb) {
213 int result;
214 for (result = sb.length(); result > 0; result --) {
215 if (!Character.isWhitespace(sb.charAt(result - 1))) {
216 break;
217 }
218 }
219 return result;
220 }
221
222 }