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.handler.codec.http.HttpConstants;
21
22
23
24
25 public abstract class AbstractHttpData implements HttpData {
26
27 protected final String name;
28 protected long definedSize;
29 protected long size;
30 protected Charset charset = HttpConstants.DEFAULT_CHARSET;
31 protected boolean completed;
32
33 public AbstractHttpData(String name, Charset charset, long size) {
34 if (name == null) {
35 throw new NullPointerException("name");
36 }
37 name = name.trim();
38 if (name.length() == 0) {
39 throw new IllegalArgumentException("empty name");
40 }
41
42 for (int i = 0; i < name.length(); i ++) {
43 char c = name.charAt(i);
44 if (c > 127) {
45 throw new IllegalArgumentException(
46 "name contains non-ascii character: " + name);
47 }
48
49
50 switch (c) {
51 case '=':
52 case ',':
53 case ';':
54 case ' ':
55 case '\t':
56 case '\r':
57 case '\n':
58 case '\f':
59 case 0x0b:
60 throw new IllegalArgumentException(
61 "name contains one of the following prohibited characters: " +
62 "=,; \\t\\r\\n\\v\\f: " + name);
63 }
64 }
65 this.name = name;
66 if (charset != null) {
67 setCharset(charset);
68 }
69 definedSize = size;
70 }
71
72 public String getName() {
73 return name;
74 }
75
76 public boolean isCompleted() {
77 return completed;
78 }
79
80 public Charset getCharset() {
81 return charset;
82 }
83
84 public void setCharset(Charset charset) {
85 if (charset == null) {
86 throw new NullPointerException("charset");
87 }
88 this.charset = charset;
89 }
90
91 public long length() {
92 return size;
93 }
94 }